ZQuest Classic Coverage Report


Directory: src/
File: src/zc/script_drawing.cpp
Date: 2024-05-09 00:53:56
Exec Total Coverage
Lines: 1386 5098 27.2%
Functions: 50 103 48.5%
Branches: 614 2631 23.3%

Line Branch Exec Source
1 // This program is free software; you can redistribute it and/or modify it under the terms of the
2 // modified version 3 of the GNU General Public License. See License.txt for details.
3
4 //! ritate_sprite_trans doesn't seem to be supported by or allegro header !?
5
6 //glibc 2.28 and later require this: -Z
7 #ifdef __GNUG__
8 #define ALLEGRO_NO_FIX_ALIASES
9 #endif
10
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include "base/zc_alleg.h"
14 #include "zc/script_drawing.h"
15 #include "zc/rendertarget.h"
16 #include "zc/maps.h"
17 #include "tiles.h"
18 #include "zc/zelda.h"
19 #include "zc/ffscript.h"
20 #include "base/util.h"
21 #include "subscr.h"
22 #include "drawing.h"
23 #include "base/mapscr.h"
24 #include "base/misctypes.h"
25 using namespace util;
26 extern FFScript FFCore;
27 extern ZModule zcm;
28 extern refInfo *ri;
29 extern script_bitmaps scb;
30 #include <stdio.h>
31 #include <fstream>
32
33 #define DegtoFix(d) ((d)*0.7111111111111)
34 #define RadtoFix(d) ((d)*40.743665431525)
35
36 inline double sd_log2( double n )
37 {
38 // log(n)/log(2) is log2.
39 double v = log( (double)n ) / log( (double)2 );
40 return v;
41 }
42
43 inline bool isPowerOfTwo(int32_t n)
44 {
45 if(n==0)
46 return false;
47
48 return (ceil(sd_log2(n)) == floor(sd_log2(n)));
49 }
50
51
52
53 template<class T> inline
54 241609 fixed degrees_to_fixed(T d)
55 {
56 241609 return ftofix(DegtoFix(d));
57 }
58 template<class T> inline
59 fixed radians_to_fixed(T d)
60 {
61 return ftofix(RadtoFix(d));
62 }
63
64 BITMAP* ScriptDrawingBitmapPool::_parent_bmp = 0;
65
66 class TileHelper
67 {
68 public:
69
70 46094 static void OldPutTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
71 {
72 // Past the end of the tile page?
73
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46094 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46094 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
74 {
75 byte w2=(tile+w)%TILES_PER_ROW;
76 OldPutTile(_Dest, tile, x, y, w-w2, h, color, flip);
77 OldPutTile(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip);
78 return;
79 }
80
81
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 46094 times.
46094 switch(flip)
82 {
83 case 1:
84 for(int32_t j=0; j<h; j++)
85 for(int32_t k=w-1; k>=0; k--)
86 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip);
87
88 break;
89
90 case 2:
91 for(int32_t j=h-1; j>=0; j--)
92 for(int32_t k=0; k<w; k++)
93 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip);
94
95 break;
96
97 case 3:
98 for(int32_t j=h-1; j>=0; j--)
99 for(int32_t k=w-1; k>=0; k--)
100 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip);
101
102 break;
103
104 46094 case 0:
105 default:
106
2/2
✓ Branch 0 taken 181240 times.
✓ Branch 1 taken 46094 times.
227334 for(int32_t j=0; j<h; j++)
107
2/2
✓ Branch 0 taken 1111148 times.
✓ Branch 1 taken 181240 times.
1292388 for(int32_t k=0; k<w; k++)
108 1292388 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip);
109
110 46094 break;
111 }
112 46094 }
113
114 3792825 static void OverTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
115 {
116 3792825 overtileblock16(_Dest,tile,x,y,w,h,color,flip,skiprows);
117 3792825 }
118
119 static void OverTileCloaked(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t flip, byte skiprows=0)
120 {
121 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
122 {
123 byte w2=(tile+w)%TILES_PER_ROW;
124 OverTileCloaked(_Dest, tile, x, y, w-w2, h, flip);
125 OverTileCloaked(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, flip);
126 return;
127 }
128
129 switch(flip)
130 {
131 case 1:
132 for(int32_t j=0; j<h; j++)
133 for(int32_t k=w-1; k>=0; k--)
134 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, flip);
135
136 break;
137
138 case 2:
139 for(int32_t j=h-1; j>=0; j--)
140 for(int32_t k=0; k<w; k++)
141 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, flip);
142
143 break;
144
145 case 3:
146 for(int32_t j=h-1; j>=0; j--)
147 for(int32_t k=w-1; k>=0; k--)
148 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, flip);
149
150 break;
151
152 default:
153 for(int32_t j=0; j<h; j++)
154 for(int32_t k=0; k<w; k++)
155 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, flip);
156
157 break;
158 }
159 }
160
161 281546 static void OverTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
162 {
163
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 281546 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
281546 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
164 {
165 byte w2=(tile+w)%TILES_PER_ROW;
166 OverTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
167 OverTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
168 return;
169 }
170
171
1/4
✓ Branch 0 taken 281546 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
281546 switch(flip)
172 {
173 case 1:
174 for(int32_t j=0; j<h; j++)
175 for(int32_t k=w-1; k>=0; k--)
176 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
177
178 break;
179
180 case 2:
181 for(int32_t j=h-1; j>=0; j--)
182 for(int32_t k=0; k<w; k++)
183 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
184
185 break;
186
187 case 3:
188 for(int32_t j=h-1; j>=0; j--)
189 for(int32_t k=w-1; k>=0; k--)
190 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
191
192 break;
193
194 default:
195
2/2
✓ Branch 0 taken 1662164 times.
✓ Branch 1 taken 281546 times.
1943710 for(int32_t j=0; j<h; j++)
196
2/2
✓ Branch 0 taken 23535905 times.
✓ Branch 1 taken 1662164 times.
25198069 for(int32_t k=0; k<w; k++)
197 25198069 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
198
199 281546 break;
200 }
201 281546 }
202
203 static void PutTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
204 {
205 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
206 {
207 byte w2=(tile+w)%TILES_PER_ROW;
208 PutTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
209 PutTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
210 return;
211 }
212
213 switch(flip)
214 {
215 case 1:
216 for(int32_t j=0; j<h; j++)
217 for(int32_t k=w-1; k>=0; k--)
218 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
219
220 break;
221
222 case 2:
223 for(int32_t j=h-1; j>=0; j--)
224 for(int32_t k=0; k<w; k++)
225 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
226
227 break;
228
229 case 3:
230 for(int32_t j=h-1; j>=0; j--)
231 for(int32_t k=w-1; k>=0; k--)
232 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
233
234 break;
235
236 default:
237 for(int32_t j=0; j<h; j++)
238 for(int32_t k=0; k<w; k++)
239 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
240
241 break;
242 }
243 }
244 };
245
246
247
248
249 2329703 void do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
250 {
251 //sdci[1]=layer
252 //sdci[2]=x
253 //sdci[3]=y
254 //sdci[4]=x2
255 //sdci[5]=y2
256 //sdci[6]=color
257 //sdci[7]=scale factor
258 //sdci[8]=rotation anchor x
259 //sdci[9]=rotation anchor y
260 //sdci[10]=rotation angle
261 //sdci[11]=fill
262 //sdci[12]=opacity
263
1/2
✓ Branch 0 taken 2329703 times.
✗ Branch 1 not taken.
2329703 if(sdci[7]==0) //scale
264 {
265 return;
266 }
267
268 2329703 int32_t x1=sdci[2]/10000;
269 2329703 int32_t y1=sdci[3]/10000;
270 2329703 int32_t x2=sdci[4]/10000;
271 2329703 int32_t y2=sdci[5]/10000;
272
273
1/2
✓ Branch 0 taken 2329703 times.
✗ Branch 1 not taken.
2329703 if(x1>x2)
274 {
275 zc_swap(x1,x2);
276 }
277
278
2/2
✓ Branch 0 taken 2310187 times.
✓ Branch 1 taken 19516 times.
2329703 if(y1>y2)
279 {
280 19516 zc_swap(y1,y2);
281 19516 }
282
283
2/2
✓ Branch 0 taken 2328026 times.
✓ Branch 1 taken 1677 times.
2329703 if(sdci[7] != 10000)
284 {
285 1677 int32_t w=x2-x1+1;
286 1677 int32_t h=y2-y1+1;
287 1677 int32_t w2=(w*sdci[7])/10000;
288 1677 int32_t h2=(h*sdci[7])/10000;
289 1677 x1=x1-((w2-w)/2);
290 1677 x2=x2+((w2-w)/2);
291 1677 y1=y1-((h2-h)/2);
292 1677 y2=y2+((h2-h)/2);
293 1677 }
294
295 2329703 int32_t color=sdci[6]/10000;
296
297
2/2
✓ Branch 0 taken 2293224 times.
✓ Branch 1 taken 36479 times.
2329703 if(sdci[12]/10000<=127) //translucent
298 {
299 36479 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
300 36479 }
301
302
2/2
✓ Branch 0 taken 82060 times.
✓ Branch 1 taken 2247643 times.
2329703 if(sdci[10]==0) //no rotation
303 {
304
2/2
✓ Branch 0 taken 724180 times.
✓ Branch 1 taken 1523463 times.
2247643 if(sdci[11]) //filled
305 {
306 1523463 rectfill(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
307 1523463 }
308 else //outline
309 {
310 724180 rect(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
311 }
312 2247643 }
313 else //rotate
314 {
315 int32_t xy[16];
316 82060 int32_t rx=sdci[8]/10000;
317 82060 int32_t ry=sdci[9]/10000;
318 82060 fixed ra1=itofix(sdci[10]%10000)/10000;
319 82060 fixed ra2=itofix(sdci[10]/10000);
320 82060 fixed ra=ra1+ra2;
321 82060 ra = (ra/360)*256;
322
323 82060 fixed fcosa = fixcos(ra);
324 82060 fixed fsina = fixsin(ra);
325
326 82060 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
327 82060 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
328 82060 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
329 82060 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
330 82060 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
331 82060 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
332 82060 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
333 82060 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
334 82060 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
335 82060 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
336 82060 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
337 82060 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
338 82060 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
339 82060 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
340 82060 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
341 82060 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
342
343
1/2
✓ Branch 0 taken 82060 times.
✗ Branch 1 not taken.
82060 if(sdci[11]) //filled
344 {
345 82060 polygon(bmp, 4, xy, color);
346 82060 }
347 else //outline
348 {
349 line(bmp, xy[0], xy[1], xy[10], xy[11], color);
350 line(bmp, xy[2], xy[3], xy[12], xy[13], color);
351 line(bmp, xy[4], xy[5], xy[14], xy[15], color);
352 line(bmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
353 }
354 }
355
356 2329703 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
357 2329703 }
358
359 void do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
360 {
361 //sdci[1]=layer
362 //sdci[2]=x
363 //sdci[3]=y
364 //sdci[4]=tile
365 //sdci[5]=cset
366 //sdci[6]=width
367 //sdci[7]=height
368 //sdci[8]=overlay
369 //sdci[9]=opacity
370
371 int32_t x=sdci[2]/10000;
372 int32_t y=sdci[3]/10000;
373
374 int32_t tile=sdci[4]/10000;
375 int32_t cs=sdci[5]/10000;
376 int32_t w=sdci[6]/10000;
377 int32_t h=sdci[7]/10000;
378 bool overlay=sdci[8];
379 bool trans=(sdci[9]/10000<=127);
380
381 frame2x2(bmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
382 }
383
384
385
386 1130854 void do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
387 {
388 //sdci[1]=layer
389 //sdci[2]=x
390 //sdci[3]=y
391 //sdci[4]=radius
392 //sdci[5]=color
393 //sdci[6]=scale factor
394 //sdci[7]=rotation anchor x
395 //sdci[8]=rotation anchor y
396 //sdci[9]=rotation angle
397 //sdci[10]=fill
398 //sdci[11]=opacity
399
1/2
✓ Branch 0 taken 1130854 times.
✗ Branch 1 not taken.
1130854 if(sdci[6]==0) //scale
400 {
401 return;
402 }
403
404 1130854 int32_t x1=sdci[2]/10000;
405 1130854 int32_t y1=sdci[3]/10000;
406 1130854 qword r=sdci[4];
407
408
1/2
✓ Branch 0 taken 1130854 times.
✗ Branch 1 not taken.
1130854 if(sdci[6] != 10000)
409 {
410 r*=sdci[6];
411 r/=10000;
412 }
413
414 1130854 r/=10000;
415 1130854 int32_t color=sdci[5]/10000;
416
417
2/2
✓ Branch 0 taken 959832 times.
✓ Branch 1 taken 171022 times.
1130854 if(sdci[11]/10000<=127) //translucent
418 {
419 171022 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
420 171022 }
421
422
5/6
✓ Branch 0 taken 58575 times.
✓ Branch 1 taken 1072279 times.
✓ Branch 2 taken 1344 times.
✓ Branch 3 taken 57231 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1344 times.
1130854 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
423 {
424 int32_t xy[2];
425 57231 int32_t rx=sdci[7]/10000;
426 57231 int32_t ry=sdci[8]/10000;
427 57231 fixed ra1=itofix(sdci[9]%10000)/10000;
428 57231 fixed ra2=itofix(sdci[9]/10000);
429 57231 fixed ra=ra1+ra2;
430 57231 ra = (ra/360)*256;
431
432 57231 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
433 57231 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
434 57231 x1=xy[0];
435 57231 y1=xy[1];
436 57231 }
437
438
2/2
✓ Branch 0 taken 1113840 times.
✓ Branch 1 taken 17014 times.
1130854 if(sdci[10]) //filled
439 {
440 1113840 circlefill(bmp, x1+xoffset, y1+yoffset, r, color);
441 1113840 }
442 else //outline
443 {
444 17014 circle(bmp, x1+xoffset, y1+yoffset, r, color);
445 }
446
447 1130854 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
448 1130854 }
449
450
451 void do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
452 {
453 //sdci[1]=layer
454 //sdci[2]=x
455 //sdci[3]=y
456 //sdci[4]=radius
457 //sdci[5]=start angle
458 //sdci[6]=end angle
459 //sdci[7]=color
460 //sdci[8]=scale factor
461 //sdci[9]=rotation anchor x
462 //sdci[10]=rotation anchor y
463 //sdci[11]=rotation angle
464 //sdci[12]=closed
465 //sdci[13]=fill
466 //sdci[14]=opacity
467
468 if(sdci[8]==0) //scale
469 {
470 return;
471 }
472
473 int32_t cx=sdci[2]/10000;
474 int32_t cy=sdci[3]/10000;
475 qword r=sdci[4];
476
477 if(sdci[8] != 10000)
478 {
479 r*=sdci[8];
480 r/=10000;
481 }
482
483 r/=10000;
484
485 int32_t color=sdci[7]/10000;
486
487 fixed ra1=itofix(sdci[11]%10000)/10000;
488 fixed ra2=itofix(sdci[11]/10000);
489 fixed ra=ra1+ra2;
490 ra = (ra/360)*256;
491
492
493 fixed a1=itofix(sdci[5]%10000)/10000;
494 fixed a2=itofix(sdci[5]/10000);
495 fixed sa=a1+a2;
496 sa = (sa/360)*256;
497
498 a1=itofix(sdci[6]%10000)/10000;
499 a2=itofix(sdci[6]/10000);
500 fixed ea=a1+a2;
501 ea = (ea/360)*256;
502
503 if(sdci[11]!=0) //rotation
504 {
505 int32_t rx=sdci[9]/10000;
506 int32_t ry=sdci[10]/10000;
507
508 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
509 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
510 ea-=ra;
511 sa-=ra;
512 }
513
514 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
515 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
516
517 if(sdci[12]) //closed
518 {
519 if(sdci[13]) //filled
520 {
521 clear_bitmap(prim_bmp);
522 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
523 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
524 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
525 int fillx = zc_max(0,fx)+xoffset;
526 int filly = zc_max(0,fy)+yoffset;
527 zprint2("Screen->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
528 floodfill(prim_bmp, fillx, filly, color);
529
530 if(sdci[14]/10000<=127) //translucent
531 {
532 draw_trans_sprite(bmp, prim_bmp, 0,0);
533 }
534 else
535 {
536 draw_sprite(bmp, prim_bmp, 0,0);
537 }
538 }
539 else
540 {
541 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
542 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
543 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
544 }
545 }
546 else
547 {
548 if(sdci[14]/10000<=127) //translucent
549 {
550 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
551 }
552
553 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
554 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
555 }
556 }
557
558
559 1850 void do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
560 {
561 //sdci[1]=layer
562 //sdci[2]=x
563 //sdci[3]=y
564 //sdci[4]=radiusx
565 //sdci[5]=radiusy
566 //sdci[6]=color
567 //sdci[7]=scale factor
568 //sdci[8]=rotation anchor x
569 //sdci[9]=rotation anchor y
570 //sdci[10]=rotation angle
571 //sdci[11]=fill
572 //sdci[12]=opacity
573
574
1/2
✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
1850 if(sdci[7]==0) //scale
575 {
576 return;
577 }
578
579 1850 int32_t x1=sdci[2]/10000;
580 1850 int32_t y1=sdci[3]/10000;
581 1850 int32_t radx=sdci[4]/10000;
582 1850 radx*=sdci[7]/10000;
583 1850 int32_t rady=sdci[5]/10000;
584 1850 rady*=sdci[7]/10000;
585 1850 int32_t color=sdci[6]/10000;
586 1850 float rotation = sdci[10]/10000;
587
588 1850 int32_t rx=sdci[8]/10000;
589 1850 int32_t ry=sdci[9]/10000;
590 1850 fixed ra1=itofix(sdci[10]%10000)/10000;
591 1850 fixed ra2=itofix(sdci[10]/10000);
592 1850 fixed ra=ra1+ra2;
593 1850 ra = (ra/360)*256;
594
595 int32_t xy[2];
596 1850 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
597 1850 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
598 1850 x1=xy[0];
599 1850 y1=xy[1];
600
601
6/8
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 1687 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 1687 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1687 times.
1850 if(radx<1||rady<1||radx>255||rady>255) return;
602
603 1687 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
604
605
2/2
✓ Branch 0 taken 1630 times.
✓ Branch 1 taken 57 times.
1687 if(sdci[11]) //filled
606 {
607
608
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 606 times.
1630 if(sdci[12]/10000<128) //translucent
609 {
610 1024 clear_bitmap(prim_bmp);
611
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
612 1024 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
613 1024 draw_trans_sprite(bmp, prim_bmp, 0, 0);
614 1024 }
615 else // no opacity
616 {
617
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
618 606 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
619 }
620 1630 }
621 else //not filled
622 {
623
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 43 times.
57 if(sdci[12]/10000<128) //translucent
624 {
625 14 clear_bitmap(prim_bmp);
626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
627 14 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
628 14 draw_trans_sprite(bmp, prim_bmp, 0, 0);
629 14 }
630 else // no opacity
631 {
632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
633 43 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
634 }
635 }
636
637 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
638 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
639 // the ellipse, but it shouldn't be used anyway.
640
1/2
✓ Branch 0 taken 1687 times.
✗ Branch 1 not taken.
1687 if(color==0)
641 {
642 // This is very slow, so check the smallest possible square
643 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
644 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
645
646 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
647 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
648 if(getpixel(bmp, x, y)==255)
649 putpixel(bmp, x, y, 0);
650 }
651
652 1687 script_drawing_commands.ReleaseSubBitmap(bitty);
653 1850 }
654
655
656 2349855 void do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
657 {
658 //sdci[1]=layer
659 //sdci[2]=x
660 //sdci[3]=y
661 //sdci[4]=x2
662 //sdci[5]=y2
663 //sdci[6]=color
664 //sdci[7]=scale factor
665 //sdci[8]=rotation anchor x
666 //sdci[9]=rotation anchor y
667 //sdci[10]=rotation angle
668 //sdci[11]=opacity
669
1/2
✓ Branch 0 taken 2349855 times.
✗ Branch 1 not taken.
2349855 if(sdci[7]==0) //scale
670 {
671 return;
672 }
673
674 2349855 int32_t x1=sdci[2]/10000;
675 2349855 int32_t y1=sdci[3]/10000;
676 2349855 int32_t x2=sdci[4]/10000;
677 2349855 int32_t y2=sdci[5]/10000;
678
679
2/2
✓ Branch 0 taken 1901533 times.
✓ Branch 1 taken 448322 times.
2349855 if(sdci[7] != 10000)
680 {
681 448322 int32_t w=x2-x1+1;
682 448322 int32_t h=y2-y1+1;
683 448322 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
684 448322 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
685 448322 x1=x1-((w2-w)/2);
686 448322 x2=x2+((w2-w)/2);
687 448322 y1=y1-((h2-h)/2);
688 448322 y2=y2+((h2-h)/2);
689 448322 }
690
691 2349855 int32_t color=sdci[6]/10000;
692
693
1/2
✓ Branch 0 taken 2349855 times.
✗ Branch 1 not taken.
2349855 if(sdci[11]/10000<=127) //translucent
694 {
695 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
696 }
697
698
2/2
✓ Branch 0 taken 937839 times.
✓ Branch 1 taken 1412016 times.
2349855 if(sdci[10]!=0) //rotation
699 {
700 int32_t xy[4];
701 1412016 int32_t rx=sdci[8]/10000;
702 1412016 int32_t ry=sdci[9]/10000;
703 1412016 fixed ra1=itofix(sdci[10]%10000)/10000;
704 1412016 fixed ra2=itofix(sdci[10]/10000);
705 1412016 fixed ra=ra1+ra2;
706
707 1412016 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
708 1412016 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
709 1412016 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
710 1412016 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
711 1412016 x1=xy[0];
712 1412016 y1=xy[1];
713 1412016 x2=xy[2];
714 1412016 y2=xy[3];
715 1412016 }
716
717 2349855 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
718 2349855 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
719 2349855 }
720
721 void do_linesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
722 {
723 //sdci[1]=layer
724 //sdci[2]=array[10] = { x, y, x2, y2, colour, scale, rx, ry, angle, opacity }
725
726 //sdci[2]=x
727 //sdci[3]=y
728 //sdci[4]=x2
729 //sdci[5]=y2
730 //sdci[6]=color
731 //sdci[7]=scale factor
732 //sdci[8]=rotation anchor x
733 //sdci[9]=rotation anchor y
734 //sdci[10]=rotation angle
735 //sdci[11]=opacity
736 //if(sdci[7]==0) //scale
737 //{
738 // return;
739 //}
740
741 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
742
743 if(!v_ptr)
744 {
745 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
746 return;
747 }
748
749 std::vector<int32_t> &v = *v_ptr;
750
751 if(v.empty())
752 return;
753 //Z_scripterrlog("PutPixels reached line %d\n", 983);
754
755 int32_t* pos = &v[0];
756 int32_t sz = v.size();
757
758 for ( int32_t q = 0; q < sz; q+=10 )
759 {
760
761 int32_t x1 = v.at(q);
762 //Z_scripterrlog("Lines( x1 ) is: %d\n", x1);
763 int32_t y1 = v.at(q+1);
764 //Z_scripterrlog("Lines( x2 ) is: %d\n", y1);
765 int32_t x2 = v.at(q+2);
766 //Z_scripterrlog("Lines( x2 ) is: %d\n", x2);
767 int32_t y2 = v.at(q+3);
768 //Z_scripterrlog("Lines( y2 ) is: %d\n", y2);
769 int32_t color = v.at(q+4);
770 //Z_scripterrlog("Lines( colour ) is: %d\n", color);
771 //Z_scripterrlog("Lines( scale ) is: %d\n", v.at(q+5));
772 if (v.at(q+5) == 0) { Z_scripterrlog("Lines() aborting due to scale\n"); return; }//scale
773
774 if( v.at(q+5) != 10000)
775 {
776 int32_t w=x2-x1+1;
777 int32_t h=y2-y1+1;
778 int32_t w2=int32_t(w*((double)v.at(q+5)));
779 int32_t h2=int32_t(h*((double)v.at(q+5)));
780 x1=x1-((w2-w)/2);
781 x2=x2+((w2-w)/2);
782 y1=y1-((h2-h)/2);
783 y2=y2+((h2-h)/2);
784 }
785
786
787 //Z_scripterrlog("Lines( opacity ) is: %d\n", v.at(q+9));
788 if(v.at(q+9) <= 127) //translucent
789 {
790 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
791 }
792 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
793 //Z_scripterrlog("Lines( rotation ) is: %d\n", v.at(q+8));
794 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+6));
795 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+7));
796 if( v.at(q+8) !=0 ) //rotation
797 {
798 int32_t xy[4];
799
800 int32_t rx = v.at(q+6);
801
802 int32_t ry = v.at(q+7);
803
804 fixed ra1=itofix(v.at(q+8) % 1);
805 fixed ra2=itofix(v.at(q+8));
806 fixed ra=ra1+ra2;
807
808 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
809 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
810 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
811 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
812 x1=xy[0];
813 y1=xy[1];
814 x2=xy[2];
815 y2=xy[3];
816 }
817 //Z_scripterrlog("Lines( xofs ) is: %d\n", xoffset);
818 //Z_scripterrlog("Lines( yofs ) is: %d\n", yoffset);
819 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
820 }
821 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
822 }
823
824 void do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
825 {
826 //sdci[1]=layer
827 //sdci[2]=point count
828 //sdci[3]array[]
829 //sdci[4] = colour
830 //sdci[5] = opacity
831
832 int32_t col = sdci[4]/10000;
833 int32_t op = sdci[5]/10000;
834
835 //bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0) || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
836 //Z_scripterrlog("Broken offset rule for Polygon() is: %s\n", brokenOffset ? "ON" : "OFF");
837 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
838
839 if(!v_ptr)
840 {
841 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
842 return;
843 }
844
845 std::vector<int32_t> &v = *v_ptr;
846
847 if(v.empty())
848 return;
849 //Z_scripterrlog("PutPixels reached line %d\n", 983);
850
851 int32_t* pos = &v[0];
852 int32_t sz = v.size();
853 int32_t numpoints = (sdci[2]/10000);
854 if(sz & 1) --sz; //even amount only
855 if(numpoints > sz/2) //cap to array
856 numpoints = sz/2;
857 if(numpoints < 1)
858 return; //Don't draw 0 or negative point count
859
860 //Fix the draw Y offset. -Z 20th June, 2019
861 for ( int32_t q = 1; q < sz; q+=2 )
862 {
863 pos[q] += yoffset;
864 }
865 if(op <= 127) //translucent
866 {
867 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
868 }
869 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
870
871 polygon(bmp, numpoints, (int32_t*)pos, col);
872 //polygon(bmp, (sdci[2]/10000), &v, col);
873 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
874 }
875
876 void bmp_do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
877 {
878 //sdci[1]=layer
879 //sdci[2]=point count
880 //sdci[3]array[]
881 //sdci[4] = colour
882 //sdci[5] = opacity
883
884 int32_t col = sdci[4]/10000;
885 int32_t op = sdci[5]/10000;
886
887 if ( sdci[17] <= 0 )
888 {
889 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
890 return;
891 }
892 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
893 if ( refbmp == NULL ) return;
894
895 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
896
897 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
898
899 if(!v_ptr)
900 {
901 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
902 return;
903 }
904
905 std::vector<int32_t> &v = *v_ptr;
906
907 if(v.empty())
908 return;
909 //Z_scripterrlog("PutPixels reached line %d\n", 983);
910
911 int32_t* pos = &v[0];
912 int32_t sz = v.size();
913 int32_t numpoints = (sdci[2]/10000);
914 if(sz & 1) --sz; //even amount only
915 if(numpoints > sz/2) //cap to array
916 numpoints = sz/2;
917 if(numpoints < 1)
918 return; //Don't draw 0 or negative point count
919
920 //Fix the draw Y offset. -Z 20th June, 2019
921 for ( int32_t q = 1; q < sz; q+=2 )
922 {
923 pos[q] += yoffset;
924 }
925 if(op <= 127) //translucent
926 {
927 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
928 }
929 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
930
931 polygon(refbmp, numpoints, (int32_t*)pos, col);
932 //polygon(refbmp, (sdci[2]/10000), &v, col);
933 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
934 }
935
936 void do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
937 {
938 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
939
940 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
941 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
942 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
943 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
944 };
945
946 if(sdci[11]/10000 < 128) //translucent
947 {
948 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
949 }
950
951 spline(bmp, points, sdci[10]/10000);
952
953 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
954 }
955
956
957 404879 void do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
958 {
959 //sdci[1]=layer
960 //sdci[2]=x
961 //sdci[3]=y
962 //sdci[4]=color
963 //sdci[5]=rotation anchor x
964 //sdci[6]=rotation anchor y
965 //sdci[7]=rotation angle
966 //sdci[8]=opacity
967 404879 int32_t x1=sdci[2]/10000;
968 404879 int32_t y1=sdci[3]/10000;
969 404879 int32_t color=sdci[4]/10000;
970
971
2/2
✓ Branch 0 taken 404863 times.
✓ Branch 1 taken 16 times.
404879 if(sdci[8]/10000<=127) //translucent
972 {
973 16 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
974 16 }
975
976
1/2
✓ Branch 0 taken 404879 times.
✗ Branch 1 not taken.
404879 if(sdci[7]!=0) //rotation
977 {
978 int32_t xy[2];
979 int32_t rx=sdci[5]/10000;
980 int32_t ry=sdci[6]/10000;
981 fixed ra1=itofix(sdci[7]%10000)/10000;
982 fixed ra2=itofix(sdci[7]/10000);
983 fixed ra=ra1+ra2;
984
985 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
986 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
987 x1=xy[0];
988 y1=xy[1];
989 }
990
991 404879 putpixel(bmp, x1+xoffset, y1+yoffset, color);
992 404879 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
993 404879 }
994
995 void do_putpixelsr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
996 {
997 //Z_scripterrlog("Starting putpixels()%s\n");
998 //sdci[1]=layer
999 //sdci[2]=array {x,y,colour,opacity}
1000 //sdci[3]=rotation anchor x
1001 //sdci[4]=rotation anchor y
1002 //sdci[5]=rotation angle
1003
1004
1005 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1006
1007 if(!v_ptr)
1008 {
1009 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1010 return;
1011 }
1012
1013 std::vector<int32_t> &v = *v_ptr;
1014
1015 if(v.empty())
1016 return;
1017 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1018
1019 int32_t* pos = &v[0];
1020 int32_t sz = v.size();
1021 //Z_scripterrlog("Vector size is: %d\n", sz);
1022 //for ( int32_t m = 0; m < 256; ++m ) Z_scripterrlog("Vector contents at pos[%d]: %d\n", m, pos[m]);
1023
1024 //FFCore.getValues(sdci[2]/10000, points, sz);
1025
1026
1027 int32_t x1 = 0;
1028 int32_t y1 = 0;
1029
1030 for ( int32_t q = 0; q < sz; q+=4 )
1031 {
1032 //Z_scripterrlog("Vector q: %d\n", q);
1033 //if ( q > sz-1 ) break;
1034 x1 = v.at(q); //pos[q];
1035 y1 = v.at(q+1); //pos[q+1];
1036 //Z_scripterrlog("x1 is: %d\n", x1);
1037 //Z_scripterrlog("y1 is: %d\n", 1);
1038 if(sdci[5]!=0) //rotation
1039 {
1040 int32_t xy[2];
1041 int32_t rx=sdci[3]/10000;
1042 int32_t ry=sdci[4]/10000;
1043 fixed ra1=itofix(sdci[5]%10000)/10000;
1044 fixed ra2=itofix(sdci[5]/10000);
1045 fixed ra=ra1+ra2;
1046
1047 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1048 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1049 x1=xy[0];
1050 y1=xy[1];
1051 }
1052 //Z_scripterrlog("PutPixels()%s value is %d\n","x",x1);
1053 //Z_scripterrlog("PutPixels()%s value is %d\n","y",y1);
1054 //Z_scripterrlog("PutPixels()%s value is %d\n","colour",points[q+2]);
1055 if ( v.at(q+3) /*pos[q+3]*/ < 128 ) drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1056 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1057 putpixel(bmp, x1+xoffset, y1+yoffset, v.at(q+2) /*pos[q+2]*/);
1058 //if ( points[q+3] < 128 )
1059
1060 //else drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1061 }
1062 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1063 }
1064
1065 1533969 void do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1066 {
1067 //sdci[1]=layer
1068 //sdci[2]=x
1069 //sdci[3]=y
1070 //sdci[4]=tile
1071 //sdci[5]=tile width
1072 //sdci[6]=tile height
1073 //sdci[7]=color (cset)
1074 //sdci[8]=scale x
1075 //sdci[9]=scale y
1076 //sdci[10]=rotation anchor x
1077 //sdci[11]=rotation anchor y
1078 //sdci[12]=rotation angle
1079 //sdci[13]=flip
1080 //sdci[14]=transparency
1081 //sdci[15]=opacity
1082
1083 1533969 int32_t w = sdci[5]/10000;
1084 1533969 int32_t h = sdci[6]/10000;
1085
1086
4/8
✓ Branch 0 taken 1533969 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1533969 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1533969 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1533969 times.
1533969 if(w < 1 || h < 1 || h > 20 || w > 20)
1087 {
1088 return;
1089 }
1090
1091 1533969 int32_t xscale=sdci[8]/10000;
1092 1533969 int32_t yscale=sdci[9]/10000;
1093 1533969 int32_t rx = sdci[10]/10000;
1094 1533969 int32_t ry = sdci[11]/10000;
1095 1533969 float rotation=sdci[12]/10000;
1096 1533969 int32_t flip=(sdci[13]/10000)&3;
1097 1533969 bool transparency=sdci[14]!=0;
1098 1533969 int32_t opacity=sdci[15]/10000;
1099 1533969 int32_t color=sdci[7]/10000;
1100
1101 1533969 int32_t x1=sdci[2]/10000;
1102 1533969 int32_t y1=sdci[3]/10000;
1103
1104 //don't scale if it's not safe to do so
1105 1533969 bool canscale = true;
1106
1107
3/4
✓ Branch 0 taken 1513324 times.
✓ Branch 1 taken 20645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1513324 times.
1533969 if(xscale==0||yscale==0)
1108 {
1109 20645 return;
1110 }
1111
1112
3/4
✓ Branch 0 taken 138965 times.
✓ Branch 1 taken 1374359 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138965 times.
1513324 if(xscale<=0||yscale<=0)
1113 1374359 canscale = false; //default size
1114
1115
4/4
✓ Branch 0 taken 138965 times.
✓ Branch 1 taken 1374359 times.
✓ Branch 2 taken 130807 times.
✓ Branch 3 taken 1243552 times.
1513324 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1116 {
1117 269772 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
1118
1119
1/2
✓ Branch 0 taken 269772 times.
✗ Branch 1 not taken.
269772 if(transparency) //transparency
1120 {
1121 269772 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1122 269772 }
1123 else //no transparency
1124 {
1125 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1126 }
1127
1128
2/2
✓ Branch 0 taken 134495 times.
✓ Branch 1 taken 135277 times.
269772 if(rotation != 0)
1129 {
1130 //low negative values indicate no anchor-point rotation
1131
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 134495 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
134495 if(rx>-777||ry>-777)
1132 {
1133 int32_t xy[2];
1134 134495 fixed ra1=itofix(sdci[12]%10000)/10000;
1135 134495 fixed ra2=itofix(sdci[12]/10000);
1136 134495 fixed ra=ra1+ra2;
1137 134495 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1138 134495 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1139 134495 x1=xy[0];
1140 134495 y1=xy[1];
1141 134495 }
1142
1143
2/2
✓ Branch 0 taken 3688 times.
✓ Branch 1 taken 130807 times.
134495 if(canscale) //scale first
1144 {
1145 //damnit all, .. fixme.
1146
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3688 times.
3688 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1147 3688 clear_bitmap(tempbit);
1148
1149 3688 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1150
1151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
3688 if(opacity < 128)
1152 {
1153 clear_bitmap(prim_bmp);
1154 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1155 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1156 }
1157 else
1158 {
1159 3688 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1160 }
1161
1162 3688 destroy_bitmap(tempbit);
1163 3688 }
1164 else //no scale
1165 {
1166
2/2
✓ Branch 0 taken 3586 times.
✓ Branch 1 taken 127221 times.
130807 if(opacity < 128)
1167 {
1168 3586 clear_bitmap(prim_bmp);
1169 3586 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1170 3586 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1171 3586 }
1172 else
1173 {
1174 127221 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1175 }
1176 }
1177 134495 }
1178 else //scale only
1179 {
1180
1/2
✓ Branch 0 taken 135277 times.
✗ Branch 1 not taken.
135277 if(canscale)
1181 {
1182
2/2
✓ Branch 0 taken 2832 times.
✓ Branch 1 taken 132445 times.
135277 if(opacity<128)
1183 {
1184 2832 clear_bitmap(prim_bmp);
1185 2832 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1186 2832 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1187 2832 }
1188 else
1189 {
1190 132445 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1191 }
1192 135277 }
1193 else //error -do not scale
1194 {
1195 if(opacity<128)
1196 {
1197 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1198 }
1199 else
1200 {
1201 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1202 }
1203 }
1204 }
1205
1206 269772 script_drawing_commands.ReleaseSubBitmap(pbitty);
1207
1208 269772 }
1209 else // no scale or rotation
1210 {
1211
2/2
✓ Branch 0 taken 1216098 times.
✓ Branch 1 taken 27454 times.
1243552 if(transparency)
1212 {
1213
2/2
✓ Branch 0 taken 220666 times.
✓ Branch 1 taken 995432 times.
1216098 if(opacity<=127)
1214 220666 TileHelper::OverTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1215 else
1216 995432 TileHelper::OverTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1217 1216098 }
1218 else
1219 {
1220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27454 times.
27454 if(opacity<=127)
1221 TileHelper::PutTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1222 else
1223 27454 TileHelper::OldPutTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1224 }
1225 }
1226 1533969 }
1227
1228 void do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1229 {
1230 //sdci[1]=layer
1231 //sdci[2]=x
1232 //sdci[3]=y
1233 //sdci[4]=tile
1234 //sdci[5]=tile width
1235 //sdci[6]=tile height
1236 //sdci[7]=flip
1237
1238 int32_t w = sdci[5]/10000;
1239 int32_t h = sdci[6]/10000;
1240
1241 if(w < 1 || h < 1 || h > 20 || w > 20)
1242 {
1243 return;
1244 }
1245
1246 int32_t flip=(sdci[7]/10000)&3;
1247
1248 int32_t x1=sdci[2]/10000;
1249 int32_t y1=sdci[3]/10000;
1250
1251 TileHelper::OverTileCloaked(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
1252 }
1253
1254
1255 2537283 void do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1256 {
1257 //sdci[1]=layer
1258 //sdci[2]=x
1259 //sdci[3]=y
1260 //sdci[4]=combo
1261 //sdci[5]=tile width
1262 //sdci[6]=tile height
1263 //sdci[7]=color (cset)
1264 //sdci[8]=scale x
1265 //sdci[9]=scale y
1266 //sdci[10]=rotation anchor x
1267 //sdci[11]=rotation anchor y
1268 //sdci[12]=rotation angle
1269 //sdci[13]=frame
1270 //sdci[14]=flip
1271 //sdci[15]=transparency
1272 //sdci[16]=opacity
1273
1274 2537283 int32_t w = sdci[5]/10000;
1275 2537283 int32_t h = sdci[6]/10000;
1276
1277
4/8
✓ Branch 0 taken 2537283 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2537283 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2537283 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2537283 times.
2537283 if(w<1||h<1||h>20||w>20)
1278 {
1279 return;
1280 }
1281 2537283 int32_t cmb = (sdci[4]/10000);
1282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2537283 times.
2537283 if((unsigned)cmb >= MAXCOMBOS)
1283 {
1284 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1285 return;
1286 }
1287
1288 2537283 int32_t xscale=sdci[8]/10000;
1289 2537283 int32_t yscale=sdci[9]/10000;
1290 2537283 int32_t rx = sdci[10]/10000; //these work now
1291 2537283 int32_t ry = sdci[11]/10000; //these work now
1292 2537283 float rotation=sdci[12]/10000;
1293
1294 2537283 bool transparency=sdci[15]!=0;
1295 2537283 int32_t opacity=sdci[16]/10000;
1296 2537283 int32_t color=sdci[7]/10000;
1297 2537283 int32_t x1=sdci[2]/10000;
1298 2537283 int32_t y1=sdci[3]/10000;
1299
1300 2537283 const newcombo & c = combobuf[cmb];
1301 2537283 int32_t tiletodraw = combo_tile(c, x1, y1);
1302 2537283 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
1303 2537283 int32_t skiprows=c.skipanimy;
1304
1305
1306 //don't scale if it's not safe to do so
1307 2537283 bool canscale = true;
1308
1309
3/4
✓ Branch 0 taken 2537235 times.
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2537235 times.
2537283 if(xscale==0||yscale==0)
1310 {
1311 48 return;
1312 }
1313
1314
3/4
✓ Branch 0 taken 22391 times.
✓ Branch 1 taken 2514844 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22391 times.
2537235 if(xscale<=0||yscale<=0)
1315 2514844 canscale = false; //default size
1316
1317
4/4
✓ Branch 0 taken 22391 times.
✓ Branch 1 taken 2514844 times.
✓ Branch 2 taken 98637 times.
✓ Branch 3 taken 2416207 times.
2537235 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1318 {
1319 121028 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
1320
1321
2/2
✓ Branch 0 taken 119992 times.
✓ Branch 1 taken 1036 times.
121028 if(transparency)
1322 {
1323 119992 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1324 119992 }
1325 else //no transparency
1326 {
1327 1036 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1328 }
1329
1330
2/2
✓ Branch 0 taken 98746 times.
✓ Branch 1 taken 22282 times.
121028 if(rotation != 0) // rotate
1331 {
1332 //fixed point sucks ;0
1333
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 98746 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
98746 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
1334 {
1335 int32_t xy[2];
1336 98746 fixed ra1=itofix(sdci[12]%10000)/10000;
1337 98746 fixed ra2=itofix(sdci[12]/10000);
1338 98746 fixed ra=ra1+ra2;
1339 98746 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1340 98746 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1341 98746 x1=xy[0];
1342 98746 y1=xy[1];
1343 98746 }
1344
1345
2/2
✓ Branch 0 taken 109 times.
✓ Branch 1 taken 98637 times.
98746 if(canscale) //scale first
1346 {
1347
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 109 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 109 times.
109 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1348 109 clear_bitmap(tempbit);
1349
1350 109 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1351
1352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 109 times.
109 if(opacity < 128)
1353 {
1354 clear_bitmap(prim_bmp);
1355 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1356 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1357 }
1358 else
1359 {
1360 109 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1361 }
1362
1363 109 destroy_bitmap(tempbit);
1364 109 }
1365 else //no scale
1366 {
1367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98637 times.
98637 if(opacity < 128)
1368 {
1369 clear_bitmap(prim_bmp);
1370 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1371 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1372 }
1373 else
1374 {
1375 98637 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1376 }
1377 }
1378 98746 }
1379 else //scale only
1380 {
1381
1/2
✓ Branch 0 taken 22282 times.
✗ Branch 1 not taken.
22282 if(canscale)
1382 {
1383
2/2
✓ Branch 0 taken 9291 times.
✓ Branch 1 taken 12991 times.
22282 if(opacity<128)
1384 {
1385 9291 clear_bitmap(prim_bmp);
1386 9291 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1387 9291 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1388 9291 }
1389 else
1390 {
1391 12991 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1392 }
1393 22282 }
1394 else //error -do not scale
1395 {
1396 if(opacity<128)
1397 {
1398 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1399 }
1400 else
1401 {
1402 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1403 }
1404 }
1405 }
1406
1407 121028 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
1408 121028 }
1409 else // no scale or rotation
1410 {
1411
1/2
✓ Branch 0 taken 2416207 times.
✗ Branch 1 not taken.
2416207 if(transparency)
1412 {
1413
2/2
✓ Branch 0 taken 60880 times.
✓ Branch 1 taken 2355327 times.
2416207 if(opacity<=127)
1414 60880 TileHelper::OverTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1415 else
1416 2355327 TileHelper::OverTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1417 2416207 }
1418 else
1419 {
1420 if(opacity<=127)
1421 TileHelper::PutTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1422 else
1423 TileHelper::OldPutTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1424 }
1425 }
1426 2537283 }
1427
1428 void do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1429 {
1430 //sdci[1]=layer
1431 //sdci[2]=x
1432 //sdci[3]=y
1433 //sdci[4]=combo
1434 //sdci[5]=tile width
1435 //sdci[6]=tile height
1436 //sdci[7]=flip
1437
1438 int32_t w = sdci[5]/10000;
1439 int32_t h = sdci[6]/10000;
1440
1441 if(w<1||h<1||h>20||w>20)
1442 {
1443 return;
1444 }
1445 int32_t cmb = (sdci[4]/10000);
1446 if((unsigned)cmb >= MAXCOMBOS)
1447 {
1448 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1449 return;
1450 }
1451
1452 int32_t x1=sdci[2]/10000;
1453 int32_t y1=sdci[3]/10000;
1454
1455 const newcombo & c = combobuf[cmb];
1456 int32_t tiletodraw = combo_tile(c, x1, y1);
1457 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
1458 int32_t skiprows=c.skipanimy;
1459
1460 TileHelper::OverTileCloaked(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
1461 }
1462
1463
1464 5287220 void do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1465 {
1466 /* layer, x, y, tile, color opacity */
1467
1468 5287220 int32_t opacity = sdci[6]/10000;
1469
1470
2/2
✓ Branch 0 taken 153668 times.
✓ Branch 1 taken 5133552 times.
5287220 if(opacity < 128)
1471 153668 overtiletranslucent16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
1472 else
1473 5133552 overtile16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
1474 5287220 }
1475
1476 void do_fasttilesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1477 {
1478 /* layer, x, y, tile, color opacity */
1479
1480 //sdci[1]=layer
1481 //sdci[2]=array {x,y,tile,colour,opacity}
1482
1483 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1484
1485 if(!v_ptr)
1486 {
1487 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1488 return;
1489 }
1490
1491 std::vector<int32_t> &v = *v_ptr;
1492
1493 if(v.empty())
1494 return;
1495 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1496
1497 int32_t* pos = &v[0];
1498 int32_t sz = v.size();
1499
1500 for ( int32_t q = 0; q < sz; q+=5 )
1501 {
1502
1503 if(v.at(q+4) < 128)
1504 overtiletranslucent16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0, v.at(q+4));
1505 else
1506 overtile16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0);
1507 }
1508 }
1509
1510
1511
1512 21409189 void do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1513 {
1514 /* layer, x, y, tile, color opacity */
1515
1516 21409189 int32_t opacity = sdci[6] / 10000;
1517 21409189 int32_t x1 = sdci[2] / 10000;
1518 21409189 int32_t y1 = sdci[3] / 10000;
1519
1520 21409189 int32_t cmb = (sdci[4]/10000);
1521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21409189 times.
21409189 if((unsigned)cmb >= MAXCOMBOS)
1522 {
1523 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1524 return;
1525 }
1526 //if( index >= MAXCOMBOS ) return; //bleh.
1527 /*
1528 const newcombo & c = combobuf[index];
1529
1530 if(opacity < 128)
1531 overtiletranslucent16(bmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip, opacity);
1532 else
1533 overtile16(bmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip);
1534 */
1535
1536
2/2
✓ Branch 0 taken 177396 times.
✓ Branch 1 taken 21231793 times.
21409189 if(opacity < 128)
1537 {
1538 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
1539 177396 overcomboblocktranslucent(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
1540
1541 177396 }
1542 else
1543 {
1544 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
1545 21231793 overcomboblock(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
1546 }
1547 21409189 }
1548
1549 void do_fastcombosr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1550 {
1551 /* layer, x, y, combo, cset, opacity */
1552
1553 //sdci[1]=layer
1554 //sdci[2]=array {x,y,combo,cset,opacity}
1555
1556 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1557
1558 if(!v_ptr)
1559 {
1560 al_trace("Screen->FastCombos: Vector pointer is null! Internal error. \n");
1561 return;
1562 }
1563
1564 std::vector<int32_t> &v = *v_ptr;
1565
1566 if(v.empty())
1567 return;
1568
1569 int32_t* pos = &v[0];
1570 int32_t sz = v.size();
1571
1572 for ( int32_t q = 0; q < sz; q+=5 )
1573 {
1574 if((unsigned)(v.at(q+2)) >= MAXCOMBOS)
1575 {
1576 Z_scripterrlog("FastCombos() cannot draw combo '%d', as it is out of bounds.\n", v.at(q+2));
1577 continue;
1578 }
1579 if(v.at(q+4) < 128)
1580 {
1581 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
1582 overcomboblocktranslucent(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1, 128);
1583
1584 }
1585 else
1586 {
1587 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
1588 overcomboblock(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1);
1589 }
1590 }
1591 }
1592
1593
1594
1595
1596 962949 void do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1597 {
1598 //broken 2.50.2 and earlier drawcharacter()
1599
2/2
✓ Branch 0 taken 17778 times.
✓ Branch 1 taken 945171 times.
962949 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1600 {
1601 //sdci[1]=layer
1602 //sdci[2]=x
1603 //sdci[3]=y
1604 //sdci[4]=font
1605 //sdci[5]=color
1606 //sdci[6]=bg color
1607 //sdci[7]=strech x (width)
1608 //sdci[8]=stretch y (height)
1609 //sdci[9]=char
1610 //sdci[10]=opacity
1611
1612 17778 int32_t x=sdci[2]/10000;
1613 17778 int32_t y=sdci[3]/10000;
1614 17778 int32_t font_index=sdci[4]/10000;
1615 17778 int32_t color=sdci[5]/10000;
1616 17778 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1617 17778 int32_t w=sdci[7]/10000;
1618 17778 int32_t h=sdci[8]/10000;
1619 17778 char glyph=char(sdci[9]/10000);
1620 17778 int32_t opacity=sdci[10]/10000;
1621
1622 //safe check
1623
1/2
✓ Branch 0 taken 17778 times.
✗ Branch 1 not taken.
17778 if(bg_color < -1) bg_color = -1;
1624
1625
1/2
✓ Branch 0 taken 17778 times.
✗ Branch 1 not taken.
17778 if(w>512) w=512; //w=vbound(w,0,512);
1626
1627
1/2
✓ Branch 0 taken 17778 times.
✗ Branch 1 not taken.
17778 if(h>512) h=512; //h=vbound(h,0,512);
1628
1629 //undone
1630
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17778 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17778 if(w>0&&h>0)//stretch the character
1631 {
1632 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1633
1634 if(opacity < 128)
1635 {
1636 if(w>128||h>128)
1637 {
1638 clear_bitmap(prim_bmp);
1639
1640 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1641 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1642 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1643 }
1644 else //this is faster
1645 {
1646 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1647
1648 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1649 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1650 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1651
1652 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1653 }
1654 }
1655 else // no opacity
1656 {
1657 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1658 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1659 }
1660
1661 }
1662 else //no stretch
1663 {
1664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17778 times.
17778 if(opacity < 128)
1665 {
1666 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1667 clear_bitmap(pbmp);
1668
1669 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1670 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1671
1672 destroy_bitmap(pbmp);
1673 }
1674 else // no opacity
1675 {
1676 17778 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1677 }
1678 }
1679 17778 }
1680
1681 else //2.53.0 fixed version and later.
1682 {
1683
1684 //sdci[1]=layer
1685 //sdci[2]=x
1686 //sdci[3]=y
1687 //sdci[4]=font
1688 //sdci[5]=color
1689 //sdci[6]=bg color
1690 //sdci[7]=strech x (width)
1691 //sdci[8]=stretch y (height)
1692 //sdci[9]=char
1693 //sdci[10]=opacity
1694
1695 945171 int32_t x=sdci[2]/10000;
1696 945171 int32_t y=sdci[3]/10000;
1697 945171 int32_t font_index=sdci[4]/10000;
1698 945171 int32_t color=sdci[5]/10000;
1699 945171 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1700 945171 int32_t w=sdci[7]/10000;
1701 945171 int32_t h=sdci[8]/10000;
1702 945171 char glyph=char(sdci[9]/10000);
1703 945171 int32_t opacity=sdci[10]/10000;
1704
1705 //safe check
1706
1/2
✓ Branch 0 taken 945171 times.
✗ Branch 1 not taken.
945171 if(bg_color < -1) bg_color = -1;
1707
1708
1/2
✓ Branch 0 taken 945171 times.
✗ Branch 1 not taken.
945171 if(w>512) w=512; //w=vbound(w,0,512);
1709
1710
1/2
✓ Branch 0 taken 945171 times.
✗ Branch 1 not taken.
945171 if(h>512) h=512; //h=vbound(h,0,512);
1711
1712 //undone
1713
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 945171 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
945171 if(w>0&&h>0)//stretch the character
1714 {
1715 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1716
1717 if(opacity < 128)
1718 {
1719 if(w>128||h>128)
1720 {
1721 clear_bitmap(prim_bmp);
1722
1723 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1724 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1725 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1726 }
1727 else //this is faster
1728 {
1729 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1730
1731 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1732 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1733 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1734
1735 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1736 }
1737 }
1738 else // no opacity
1739 {
1740 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1741 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1742 }
1743
1744 }
1745 else //no stretch
1746 {
1747
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 945171 times.
945171 if(opacity < 128)
1748 {
1749 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1750 clear_bitmap(pbmp);
1751
1752 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1753 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1754
1755 destroy_bitmap(pbmp);
1756 }
1757 else // no opacity
1758 {
1759 945171 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1760 }
1761 }
1762
1763 }
1764
1765 962949 }
1766
1767
1768 142863 void do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1769 {
1770 //broken 2.50.2 and earlier drawinteger()
1771
2/2
✓ Branch 0 taken 72533 times.
✓ Branch 1 taken 70330 times.
142863 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1772 {
1773 //sdci[1]=layer
1774 //sdci[2]=x
1775 //sdci[3]=y
1776 //sdci[4]=font
1777 //sdci[5]=color
1778 //sdci[6]=bg color
1779 //sdci[7]=strech x (width)
1780 //sdci[8]=stretch y (height)
1781 //sdci[9]=integer
1782 //sdci[10]=num decimal places
1783 //sdci[11]=opacity
1784
1785 72533 int32_t x=sdci[2]/10000;
1786 72533 int32_t y=sdci[3]/10000;
1787 72533 int32_t font_index=sdci[4]/10000;
1788 72533 int32_t color=sdci[5]/10000;
1789 72533 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1790 72533 int32_t w=sdci[7]/10000;
1791 72533 int32_t h=sdci[8]/10000;
1792 //float number=static_cast<float>(sdci[9])/10000.0f;
1793 72533 int32_t decplace=sdci[10]/10000;
1794 72533 int32_t opacity=sdci[11]/10000;
1795
1796 //safe check
1797
1/2
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
72533 if(bg_color < -1) bg_color = -1;
1798
1799
1/2
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
72533 if(w>512) w=512; //w=vbound(w,0,512);
1800
1801
1/2
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
72533 if(h>512) h=512; //h=vbound(h,0,512);
1802
1803 char numbuf[15];
1804
1805
1/6
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
72533 switch(decplace)
1806 {
1807 default:
1808 case 0:
1809 72533 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1810 72533 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1811
1812 case 1:
1813 //sprintf(numbuf,"%.01f",number);
1814 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1815 break;
1816
1817 case 2:
1818 //sprintf(numbuf,"%.02f",number);
1819 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1820 break;
1821
1822 case 3:
1823 //sprintf(numbuf,"%.03f",number);
1824 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1825 break;
1826
1827 case 4:
1828 //sprintf(numbuf,"%.04f",number);
1829 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1830 break;
1831 }
1832
1833
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 72533 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
72533 if(w>0&&h>0)//stretch
1834 {
1835 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1836
1837 if(opacity < 128)
1838 {
1839 if(w>128||h>128)
1840 {
1841 clear_bitmap(prim_bmp);
1842
1843 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1844 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1845 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1846 }
1847 else
1848 {
1849 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1850 clear_bitmap(pbmp2);
1851
1852 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1853 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1854 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1855
1856 destroy_bitmap(pbmp2);
1857 }
1858 }
1859 else // no opacity
1860 {
1861 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1862 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1863 }
1864
1865 }
1866 else //no stretch
1867 {
1868
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72533 times.
72533 if(opacity < 128)
1869 {
1870 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1871 clear_bitmap(pbmp);
1872
1873 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1874 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1875
1876 destroy_bitmap(pbmp);
1877 }
1878 else // no opacity
1879 {
1880 72533 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1881 }
1882 }
1883
1884 72533 }
1885
1886 else //2.53.0 fixed version and later.
1887 {
1888 //sdci[1]=layer
1889 //sdci[2]=x
1890 //sdci[3]=y
1891 //sdci[4]=font
1892 //sdci[5]=color
1893 //sdci[6]=bg color
1894 //sdci[7]=strech x (width)
1895 //sdci[8]=stretch y (height)
1896 //sdci[9]=integer
1897 //sdci[10]=num decimal places
1898 //sdci[11]=opacity
1899
1900 70330 int32_t x=sdci[2]/10000;
1901 70330 int32_t y=sdci[3]/10000;
1902 70330 int32_t font_index=sdci[4]/10000;
1903 70330 int32_t color=sdci[5]/10000;
1904 70330 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1905 70330 int32_t w=sdci[7]/10000;
1906 70330 int32_t h=sdci[8]/10000;
1907 //float number=static_cast<float>(sdci[9])/10000.0f;
1908 //int32_t numberint = sdci[9]/10000;
1909 70330 int32_t decplace=sdci[10]/10000;
1910 70330 int32_t opacity=sdci[11]/10000;
1911
1912 //safe check
1913
1/2
✓ Branch 0 taken 70330 times.
✗ Branch 1 not taken.
70330 if(bg_color < -1) bg_color = -1;
1914
1915
1/2
✓ Branch 0 taken 70330 times.
✗ Branch 1 not taken.
70330 if(w>512) w=512; //w=vbound(w,0,512);
1916
1917
1/2
✓ Branch 0 taken 70330 times.
✗ Branch 1 not taken.
70330 if(h>512) h=512; //h=vbound(h,0,512);
1918
1919 char numbuf[15];
1920
1921
1/6
✓ Branch 0 taken 70330 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
70330 switch(decplace)
1922 {
1923 default:
1924 case 0:
1925 70330 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1926 70330 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1927
1928 case 1:
1929 //sprintf(numbuf,"%.01f",number);
1930 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1931 break;
1932
1933 case 2:
1934 //sprintf(numbuf,"%.02f",number);
1935 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1936 break;
1937
1938 case 3:
1939 //sprintf(numbuf,"%.03f",number);
1940 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1941 break;
1942
1943 case 4:
1944 //sprintf(numbuf,"%.04f",number);
1945 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1946 break;
1947 }
1948
1949 //FONT* font=get_zc_font(sdci[4]/10000);
1950
1951
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 70330 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
70330 if(w>0&&h>0)//stretch
1952 {
1953 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
1954 clear_bitmap(pbmp);
1955 //script_drawing_commands.GetSmallTextureBitmap(1,1);
1956
1957 if(opacity < 128)
1958 {
1959 if(w>128||h>128)
1960 {
1961 clear_bitmap(prim_bmp);
1962
1963 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1964 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1965 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1966 }
1967 else
1968 {
1969 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1970 clear_bitmap(pbmp2);
1971
1972 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1973 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1974 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1975
1976 destroy_bitmap(pbmp2);
1977 }
1978 }
1979 else // no opacity
1980 {
1981 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1982 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1983 }
1984
1985 }
1986 else //no stretch
1987 {
1988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70330 times.
70330 if(opacity < 128)
1989 {
1990 FONT* font = get_zc_font(font_index);
1991 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
1992 clear_bitmap(pbmp);
1993
1994 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
1995 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1996
1997 destroy_bitmap(pbmp);
1998 }
1999 else // no opacity
2000 {
2001 70330 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
2002 }
2003 }
2004 }
2005 142863 }
2006
2007
2008 1482101 void do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2009 {
2010 //sdci[1]=layer
2011 //sdci[2]=x
2012 //sdci[3]=y
2013 //sdci[4]=font
2014 //sdci[5]=color
2015 //sdci[6]=bg color
2016 //sdci[7]=format_option
2017 //sdci[8]=string
2018 //sdci[9]=opacity
2019
2020 1482101 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2021
2022
1/2
✓ Branch 0 taken 1482101 times.
✗ Branch 1 not taken.
1482101 if(!str)
2023 {
2024 al_trace("String pointer is null! Internal error. \n");
2025 return;
2026 }
2027
2028 1482101 int32_t x=sdci[2]/10000;
2029 1482101 int32_t y=sdci[3]/10000;
2030 1482101 FONT* font=get_zc_font(sdci[4]/10000);
2031 1482101 int32_t color=sdci[5]/10000;
2032 1482101 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2033 1482101 int32_t format_type=sdci[7]/10000;
2034 1482101 int32_t opacity=sdci[9]/10000;
2035 //sdci[8] not needed :)
2036
2037 //safe check
2038
1/2
✓ Branch 0 taken 1482101 times.
✗ Branch 1 not taken.
1482101 if(bg_color < -1) bg_color = -1;
2039
2040
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1482101 times.
1482101 if(opacity < 128)
2041 {
2042 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2043 if (width < 1) return; //SANITY -Em
2044 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2045 clear_bitmap(pbmp);
2046 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2047 if(format_type == 2) // right-sided text
2048 x-=width;
2049 else if(format_type == 1) // centered text
2050 x-=width/2;
2051 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2052 destroy_bitmap(pbmp);
2053 }
2054 else // no opacity
2055 {
2056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1482101 times.
1482101 if(format_type == 2) // right-sided text
2057 {
2058 textout_right_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2059 }
2060
2/2
✓ Branch 0 taken 723406 times.
✓ Branch 1 taken 758695 times.
1482101 else if(format_type == 1) // centered text
2061 {
2062 723406 textout_centre_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2063 723406 }
2064 else // standard left-sided text
2065 {
2066 758695 textout_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2067 }
2068 }
2069 1482101 }
2070
2071 163717 void do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2072 {
2073 //sdci[1]=layer
2074 //sdci[2]=x
2075 //sdci[3]=y
2076 //sdci[4]=font
2077 //sdci[5]=color
2078 //sdci[6]=bg color
2079 //sdci[7]=format_option
2080 //sdci[8]=string
2081 //sdci[9]=opacity
2082 //sdci[10]=shadowtype
2083 //sdci[11]=shadow_color
2084
2085 163717 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2086
2087
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(!str)
2088 {
2089 al_trace("String pointer is null! Internal error. \n");
2090 return;
2091 }
2092
2093 163717 int32_t x=sdci[2]/10000;
2094 163717 int32_t y=sdci[3]/10000;
2095 163717 FONT* font=get_zc_font(sdci[4]/10000);
2096 163717 int32_t color=sdci[5]/10000;
2097 163717 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2098 163717 int32_t format_type=sdci[7]/10000;
2099 163717 int32_t opacity=sdci[9]/10000;
2100 163717 int32_t textstyle = sdci[10]/10000;
2101 163717 int32_t shadow_color = sdci[11]/10000;
2102 //sdci[8] not needed :)
2103
2104 //safe check
2105
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(bg_color < -1) bg_color = -1;
2106
2107
2/2
✓ Branch 0 taken 740 times.
✓ Branch 1 taken 162977 times.
163717 if(opacity < 128)
2108 {
2109
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2110
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 if (width < 1) return; //SANITY -Em
2111 740 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2112 740 clear_bitmap(pbmp);
2113 740 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
2114 740 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
740 if(format_type == 2) // right-sided text
2116 x-=width;
2117
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 else if(format_type == 1) // centered text
2118 740 x-=width/2;
2119 740 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2120 740 destroy_bitmap(pbmp);
2121 740 }
2122 else // no opacity
2123 {
2124 162977 textout_styled_aligned_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
2125 }
2126 163717 }
2127
2128
2129 9266 void do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2130 {
2131 //sdci[1]=layer
2132 //sdci[2]=x1
2133 //sdci[3]=y1
2134 //sdci[4]=x2
2135 //sdci[5]=y2
2136 //sdci[6]=x3
2137 //sdci[7]=y3
2138 //sdci[8]=x4
2139 //sdci[9]=y4
2140 //sdci[10]=width
2141 //sdci[11]=height
2142 //sdci[12]=cset
2143 //sdci[13]=flip
2144 //sdci[14]=tile/combo
2145 //sdci[15]=polytype
2146
2147 9266 int32_t x1 = sdci[2]/10000;
2148 9266 int32_t y1 = sdci[3]/10000;
2149 9266 int32_t x2 = sdci[4]/10000;
2150 9266 int32_t y2 = sdci[5]/10000;
2151 9266 int32_t x3 = sdci[6]/10000;
2152 9266 int32_t y3 = sdci[7]/10000;
2153 9266 int32_t x4 = sdci[8]/10000;
2154 9266 int32_t y4 = sdci[9]/10000;
2155 9266 int32_t w = sdci[10]/10000;
2156 9266 int32_t h = sdci[11]/10000;
2157 9266 int32_t color = sdci[12]/10000;
2158 9266 int32_t flip=(sdci[13]/10000)&3;
2159 9266 int32_t tile = sdci[14]/10000;
2160 9266 int32_t polytype = sdci[15]/10000;
2161
2162 //todo: finish palette shading
2163 /*
2164 POLYTYPE_FLAT
2165 POLYTYPE_GCOL
2166 POLYTYPE_GRGB
2167 POLYTYPE_ATEX
2168 POLYTYPE_PTEX
2169 POLYTYPE_ATEX_MASK
2170 POLYTYPE_PTEX_MASK
2171 POLYTYPE_ATEX_LIT
2172 POLYTYPE_PTEX_LIT
2173 POLYTYPE_ATEX_MASK_LIT
2174 POLYTYPE_PTEX_MASK_LIT
2175 POLYTYPE_ATEX_TRANS
2176 POLYTYPE_PTEX_TRANS
2177 POLYTYPE_ATEX_MASK_TRANS
2178 POLYTYPE_PTEX_MASK_TRANS
2179 */
2180 9266 polytype = vbound(polytype, 0, 14);
2181
2182
2/4
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9266 times.
9266 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2183 {
2184 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2185 return; //non power of two error
2186 }
2187
2188 9266 int32_t tex_width = w*16;
2189 9266 int32_t tex_height = h*16;
2190
2191 BITMAP *tex;
2192
2193 9266 bool mustDestroyBmp = false;
2194
2195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile > 65519 ) tex = zscriptDrawingRenderTarget->GetBitmapPtr(tile - 65519);
2196 9266 else tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2197
2198
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(!tex)
2199 {
2200 mustDestroyBmp = true;
2201 tex = create_bitmap_ex(8, tex_width, tex_height);
2202 clear_bitmap(tex);
2203 }
2204
2205 int32_t col[4];
2206 /*
2207 if( color < 0 )
2208 {
2209 col[0]=draw_container.color_buffer[0];
2210 col[1]=draw_container.color_buffer[1];
2211 col[2]=draw_container.color_buffer[2];
2212 col[3]=draw_container.color_buffer[3];
2213 }
2214 else */
2215 {
2216 9266 col[0]=col[1]=col[2]=col[3]=color;
2217 }
2218
2219
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9266 if(tile > 0 && tile <= 65519) // TILE
2220 {
2221 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2222 }
2223
2224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile < 0 ) // COMBO
2225 {
2226 9266 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2227 9266 const int32_t tiletodraw = combo_tile(c, x1, y1);
2228 9266 flip = flip ^ c.flip;
2229
2230 9266 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2231 9266 }
2232
2233 9266 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2234 9266 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2235 9266 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2236 9266 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(tex_width), 0, col[3] };
2237
2238 9266 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
2239
2240
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(mustDestroyBmp)
2241 destroy_bitmap(tex);
2242
2243 9266 }
2244
2245
2246 void do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2247 {
2248 //sdci[1]=layer
2249 //sdci[2]=x1
2250 //sdci[3]=y1
2251 //sdci[4]=x2
2252 //sdci[5]=y2
2253 //sdci[6]=x3
2254 //sdci[7]=y3
2255 //sdci[8]=width
2256 //sdci[9]=height
2257 //sdci[10]=cset
2258 //sdci[11]=flip
2259 //sdci[12]=tile/combo
2260 //sdci[13]=polytype
2261
2262 int32_t x1 = sdci[2]/10000;
2263 int32_t y1 = sdci[3]/10000;
2264 int32_t x2 = sdci[4]/10000;
2265 int32_t y2 = sdci[5]/10000;
2266 int32_t x3 = sdci[6]/10000;
2267 int32_t y3 = sdci[7]/10000;
2268 int32_t w = sdci[8]/10000;
2269 int32_t h = sdci[9]/10000;
2270 int32_t color = sdci[10]/10000;
2271 int32_t flip=(sdci[11]/10000)&3;
2272 int32_t tile = sdci[12]/10000;
2273 int32_t polytype = sdci[13]/10000;
2274
2275 polytype = vbound(polytype, 0, 14);
2276
2277 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2278 {
2279 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2280 return; //non power of two error
2281 }
2282
2283 int32_t tex_width = w*16;
2284 int32_t tex_height = h*16;
2285
2286 bool mustDestroyBmp = false;
2287 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2288
2289 if(!tex)
2290 {
2291 mustDestroyBmp = true;
2292 tex = create_bitmap_ex(8, tex_width, tex_height);
2293 clear_bitmap(tex);
2294 }
2295
2296 int32_t col[3];
2297 /*
2298 if( color < 0 )
2299 {
2300 col[0]=draw_container.color_buffer[0];
2301 col[1]=draw_container.color_buffer[1];
2302 col[2]=draw_container.color_buffer[2];
2303 }
2304 else */
2305 {
2306 col[0]=col[1]=col[2]=color;
2307 }
2308
2309 if(tile > 0) // TILE
2310 {
2311 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2312 }
2313 else // COMBO
2314 {
2315 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2316 const int32_t tiletodraw = combo_tile(c, x1, y1);
2317 flip = flip ^ c.flip;
2318
2319 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2320 }
2321
2322 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2323 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2324 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2325
2326
2327 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
2328
2329 if(mustDestroyBmp)
2330 destroy_bitmap(tex);
2331 }
2332
2333
2334 928052 void do_drawbitmapr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2335 {
2336 //sdci[1]=layer
2337 //sdci[2]=bitmap
2338 //sdci[3]=sourcex
2339 //sdci[4]=sourcey
2340 //sdci[5]=sourcew
2341 //sdci[6]=sourceh
2342 //sdci[7]=destx
2343 //sdci[8]=desty
2344 //sdci[9]=destw
2345 //sdci[10]=desth
2346 //sdci[11]=rotation
2347 //sdci[12]=mask
2348
2349 928052 int32_t bitmapIndex = sdci[2]/10000;
2350 928052 int32_t sx = sdci[3]/10000;
2351 928052 int32_t sy = sdci[4]/10000;
2352 928052 int32_t sw = sdci[5]/10000;
2353 928052 int32_t sh = sdci[6]/10000;
2354 928052 int32_t dx = sdci[7]/10000;
2355 928052 int32_t dy = sdci[8]/10000;
2356 928052 int32_t dw = sdci[9]/10000;
2357 928052 int32_t dh = sdci[10]/10000;
2358 928052 float rot = sdci[11]/10000;
2359 928052 bool masked = (sdci[12] != 0);
2360
2361 //bugfix
2362 928052 sx = vbound(sx, 0, 512);
2363 928052 sy = vbound(sy, 0, 512);
2364 928052 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2365 928052 sh = vbound(sh, 0, 512 - sy);
2366
2367
2368
2/4
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 928052 times.
928052 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2369 return;
2370
2371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 928052 times.
928052 bool stretched = (sw != dw || sh != dh);
2372
2373 928052 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2374
2375
1/2
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
928052 if(!sourceBitmap)
2376 {
2377 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2378 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2379 return;
2380 }
2381
2382 928052 BITMAP* subBmp = 0;
2383
2384
1/2
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
928052 if(rot != 0)
2385 {
2386 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2387
2388 if(!subBmp)
2389 {
2390 Z_scripterrlog("DrawBitmap() failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2391 return;
2392 }
2393 }
2394
2395
2396 928052 dx = dx + xoffset;
2397 928052 dy = dy + yoffset;
2398
2399
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 927812 times.
928052 if(stretched)
2400 {
2401
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(masked)
2402 {
2403
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(rot != 0)
2404 {
2405 //if ( rot == 4096 ) { //translucent
2406 // masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2407 // //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2408 // draw_trans_sprite(bmp, subBmp, dx, dy);
2409 // //draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, 0);
2410
2411
2412 // }
2413 //else {
2414 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2415 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2416 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2417 //
2418
2419 // }
2420 }
2421 else
2422 240 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2423 240 }
2424 else
2425 {
2426 if(rot != 0)
2427 {
2428 //if ( rot == 4096 ) { //translucent
2429 // stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2430 // draw_trans_sprite(bmp, subBmp, dx, dy);
2431 // }
2432 //else {
2433 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2434 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2435 // }
2436 }
2437 else
2438 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2439 }
2440 240 }
2441 else
2442 {
2443
2/2
✓ Branch 0 taken 923090 times.
✓ Branch 1 taken 4722 times.
927812 if(masked)
2444 {
2445
1/2
✓ Branch 0 taken 923090 times.
✗ Branch 1 not taken.
923090 if(rot != 0)
2446 {
2447 //if ( rot == 4096 ) {//translucent
2448 // masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2449 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2450
2451 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2452 //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2453 // draw_trans_sprite(bmp, subBmp, dx, dy);
2454 // }
2455 //else {
2456 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2457 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2458 // }
2459 }
2460 else
2461 923090 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2462 923090 }
2463 else
2464 {
2465
1/2
✓ Branch 0 taken 4722 times.
✗ Branch 1 not taken.
4722 if(rot != 0)
2466 {
2467 //if ( rot == 4096 ) { //translucent
2468 // blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2469 // draw_trans_sprite(bmp, subBmp, dx, dy);
2470 // }
2471 //else {
2472 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2473 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2474 // }
2475 }
2476 else
2477 4722 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2478 }
2479 }
2480
2481 //cleanup
2482
1/2
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
928052 if(subBmp)
2483 {
2484 script_drawing_commands.ReleaseSubBitmap(subBmp);
2485 }
2486 928052 }
2487
2488
2489 //Draw]()
2490 void do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2491 {
2492 /*
2493 //sdci[1]=layer
2494 //sdci[2]=bitmap
2495 //sdci[3]=sourcex
2496 //sdci[4]=sourcey
2497 //sdci[5]=sourcew
2498 //sdci[6]=sourceh
2499 //sdci[7]=destx
2500 //sdci[8]=desty
2501 //sdci[9]=destw
2502 //sdci[10]=desth
2503 //sdci[11]=rotation/angle
2504 //scdi[12] = pivot cx
2505 //sdci[13] = pivot cy
2506 //scdi[14] = effect flags
2507
2508
2509 const int32_t BITDX_NORMAL = 0;
2510 const int32_t BITDX_TRANS = 1; //Translucent
2511 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
2512 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
2513 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
2514 //Note: Some modes cannot be combined. if a combination is not supported, an error
2515 // detailing this will be shown in allegro.log.
2516
2517 //scdi[15] = litcolour
2518 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2519 /not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2520
2521 //sdci[16]=mask
2522
2523 */
2524
2525 int32_t bitmapIndex = sdci[2]/10000;
2526 int32_t sx = sdci[3]/10000;
2527 int32_t sy = sdci[4]/10000;
2528 int32_t sw = sdci[5]/10000;
2529 int32_t sh = sdci[6]/10000;
2530 int32_t dx = sdci[7]/10000;
2531 int32_t dy = sdci[8]/10000;
2532 int32_t dw = sdci[9]/10000;
2533 int32_t dh = sdci[10]/10000;
2534 float rot = sdci[11]/10000;
2535 int32_t cx = sdci[12]/10000;
2536 int32_t cy = sdci[13]/10000;
2537 int32_t mode = sdci[14]/10000;
2538 int32_t litcolour = sdci[15]/10000;
2539 bool masked = (sdci[16] != 0);
2540
2541
2542
2543 //bugfix
2544 sx = vbound(sx, 0, 512);
2545 sy = vbound(sy, 0, 512);
2546 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2547 sh = vbound(sh, 0, 512 - sy);
2548
2549
2550 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2551 return;
2552
2553 bool stretched = (sw != dw || sh != dh);
2554
2555 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2556
2557 if(!sourceBitmap)
2558 {
2559 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2560 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2561 return;
2562 }
2563
2564 BITMAP* subBmp = 0;
2565
2566 /*
2567 if ( bitmapIndex == -1 ) {
2568 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
2569 }
2570 */
2571
2572 if(rot != 0 || mode != 0)
2573 {
2574 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2575
2576 if(!subBmp)
2577 {
2578 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2579 return;
2580 }
2581 }
2582
2583
2584 dx = dx + xoffset;
2585 dy = dy + yoffset;
2586
2587 if(stretched)
2588 {
2589 if(masked) //stretched and masked
2590 {
2591 if ( rot == 0 ) //if not rotated
2592 {
2593 switch(mode)
2594 {
2595 case 1:
2596 //transparent
2597 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2598 draw_trans_sprite(bmp, subBmp, dx, dy);
2599 break;
2600
2601
2602 case 2:
2603 //pivot?
2604 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2605 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2606 //Pivoting requires two more args
2607 break;
2608
2609 case 3:
2610 //pivot + trans
2611 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2612 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2613 break;
2614
2615 case 4:
2616 //flip v
2617 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2618 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2619 break;
2620
2621 case 5:
2622 //trans + v flip
2623 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2624 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2625 break;
2626
2627 case 6:
2628 //pivot + v flip
2629 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2630 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2631 break;
2632
2633 case 8:
2634 //vlip h
2635 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2636 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2637 break;
2638
2639 case 9:
2640 //trans + h flip
2641 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2642 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2643 break;
2644
2645 case 10:
2646 //flip H and pivot
2647 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2648 //return error cannot pivot and h flip
2649 break;
2650
2651 case 12:
2652 //vh flip
2653 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2654 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2655 break;
2656
2657 case 13:
2658 //trans + vh flip
2659 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2660 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2661 break;
2662
2663 case 14:
2664 //pivot and vh flip
2665 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2666 //return error cannot both pivot and vh flip
2667 break;
2668
2669 case 16:
2670 //lit
2671 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2672 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2673 break;
2674
2675 case 18:
2676 //pivot, lit
2677 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2678 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2679 break;
2680
2681 case 20:
2682 //lit + v flip
2683 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2684 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2685 break;
2686
2687 case 22:
2688 //Pivot, vflip, lit
2689 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2690 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2691 break;
2692
2693 case 24:
2694 //lit + h flip
2695 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2696 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2697 break;
2698
2699 case 26:
2700 //pivot + lit + hflip
2701 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2702 //return error cannot pivot, lit, and flip
2703 break;
2704
2705 case 28:
2706 //lit + vh flip
2707 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2708 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2709 break;
2710
2711 case 32: //gouraud
2712 //Probably not wort supporting.
2713 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2714 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2715 break;
2716
2717 case 0:
2718 //no effect
2719 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2720 break;
2721
2722
2723 default:
2724 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2725
2726
2727 }
2728 } //end if not rotated
2729
2730 if ( rot != 0 ) //if rotated
2731 {
2732 switch(mode)
2733 {
2734 case 1:
2735 //transparent
2736 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2737 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2738
2739 break;
2740
2741 case 2:
2742 //pivot?
2743 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2744 //return an error, cannot both rotate and pivot
2745 break;
2746
2747 case 3:
2748 //pivot + trans
2749 //return an error, cannot both rotate and pivot
2750 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2751 break;
2752
2753 case 4:
2754 //flip v
2755 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2756 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2757 break;
2758
2759 case 5:
2760 //trans + v flip
2761 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2762 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2763 break;
2764
2765 case 6:
2766 //pivot + v flip
2767 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2768 //return an error, cannot both rotate and pivot
2769 break;
2770
2771 case 8:
2772 //flip h
2773 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
2774 //return an error, cannot both rotate and flip H
2775 break;
2776
2777 case 9:
2778 //trans + h flip
2779 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
2780 //return an error, cannot rotate and flip a trans sprite
2781 break;
2782
2783 case 10:
2784 //flip H and pivot
2785 //return error cannot pivot and h flip
2786 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2787 break;
2788
2789 case 12:
2790 //vh flip
2791 //return an error, cannot rotate and VH flip a trans sprite
2792 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2793 break;
2794
2795 case 13:
2796 //trans + vh flip
2797 //return an error, cannot rotate and VH flip a trans sprite
2798 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2799 break;
2800
2801 case 14:
2802 //pivot and vh flip
2803 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2804 //return error cannot both pivot and vh flip
2805 break;
2806
2807 case 16:
2808 //lit
2809 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2810 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2811 break;
2812
2813 case 18:
2814 //pivot, lit
2815 //return an error, cannot both rotate and pivot
2816 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2817 break;
2818
2819 case 20:
2820 //lit + vflip
2821 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2822 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2823 break;
2824
2825 case 22:
2826 //Pivot, vflip, lit
2827 //return an error, cannot both rotate and pivot
2828 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2829 break;
2830
2831 case 24:
2832 //lit + h flip
2833 //return an error, cannot both rotate and H flip
2834 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
2835 break;
2836
2837 case 26:
2838 //pivot + lit + hflip
2839 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
2840 //return error cannot pivot, lit, and flip
2841 break;
2842
2843 case 28:
2844 //lit + vh flip
2845 //return an error, cannot both rotate and VH flip
2846 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2847 break;
2848
2849 case 32: //gouraud
2850 //Probably not wort supporting.
2851 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2852 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2853 break;
2854
2855 case 0:
2856 //no effect.
2857 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2858 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2859 break;
2860
2861 default:
2862 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2863
2864 }
2865 }
2866 } //end if stretched and masked
2867
2868 else //stretched, not masked
2869 {
2870 if ( rot == 0 ) //if not rotated
2871 {
2872 switch(mode) {
2873 case 1:
2874 //transparent
2875 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2876 draw_trans_sprite(bmp, subBmp, dx, dy);
2877 break;
2878
2879
2880 case 2:
2881 //pivot?
2882 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2883 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2884 //Pivoting requires two more args
2885 break;
2886
2887 case 3:
2888 //pivot + trans
2889 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2890 pivot_sprite_trans(bmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
2891 break;
2892
2893 case 4:
2894 //flip v
2895 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2896 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2897 break;
2898
2899 case 5:
2900 //trans + v flip
2901 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2902 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2903 break;
2904
2905 case 6:
2906 //pivot + v flip
2907 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2908 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2909 break;
2910
2911 case 8:
2912 //vlip h
2913 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2914 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2915 break;
2916
2917 case 9:
2918 //trans + h flip
2919 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2920 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2921 break;
2922
2923 case 10:
2924 //flip H and pivot
2925 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2926 //return error cannot pivot and h flip
2927 break;
2928
2929 case 12:
2930 //vh flip
2931 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2932 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2933 break;
2934
2935 case 13:
2936 //trans + vh flip
2937 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2938 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2939 break;
2940
2941 case 14:
2942 //pivot and vh flip
2943 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2944 //return error cannot both pivot and vh flip
2945 break;
2946
2947 case 16:
2948 //lit
2949 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2950 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2951 break;
2952
2953 case 18:
2954 //pivot, lit
2955 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2956 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2957 break;
2958
2959 case 20:
2960 //lit + v flip
2961 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2962 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2963 break;
2964
2965 case 22:
2966 //Pivot, vflip, lit
2967 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2968 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2969 break;
2970
2971 case 24:
2972 //lit + h flip
2973 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2974 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2975 break;
2976
2977 case 26:
2978 //pivot + lit + hflip
2979 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2980 //return error cannot pivot, lit, and flip
2981 break;
2982
2983 case 28:
2984 //lit + vh flip
2985 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2986 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2987 break;
2988
2989 case 32: //gouraud
2990 //Probably not wort supporting.
2991 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2992 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2993 break;
2994
2995 case 0:
2996 //no effect
2997 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2998 break;
2999
3000
3001 default:
3002 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3003
3004
3005 }
3006 } //end if not rotated
3007
3008 if ( rot != 0 ) //if rotated
3009 {
3010 switch(mode)
3011 {
3012 case 1:
3013 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3014 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3015
3016 break;
3017
3018 case 2:
3019 //pivot?
3020 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3021 //return an error, cannot both rotate and pivot
3022 break;
3023
3024 case 3:
3025 //pivot + trans
3026 //return an error, cannot both rotate and pivot
3027 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3028 break;
3029
3030 case 4:
3031 //flip v
3032 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3033 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3034 break;
3035
3036 case 5:
3037 //trans + v flip
3038 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3039 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3040 break;
3041
3042 case 6:
3043 //pivot + v flip
3044 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3045 //return an error, cannot both rotate and pivot
3046 break;
3047
3048 case 8:
3049 //flip h
3050 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3051 //return an error, cannot both rotate and flip H
3052 break;
3053
3054 case 9:
3055 //trans + h flip
3056 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3057 //return an error, cannot rotate and flip a trans sprite
3058 break;
3059
3060 case 10:
3061 //flip H and pivot
3062 //return error cannot pivot and h flip
3063 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3064 break;
3065
3066 case 12:
3067 //vh flip
3068 //return an error, cannot rotate and VH flip a trans sprite
3069 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3070 break;
3071
3072 case 13:
3073 //trans + vh flip
3074 //return an error, cannot rotate and VH flip a trans sprite
3075 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3076 break;
3077
3078 case 14:
3079 //pivot and vh flip
3080 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3081 //return error cannot both pivot and vh flip
3082 break;
3083
3084 case 16:
3085 //lit
3086 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3087 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3088 break;
3089
3090 case 18:
3091 //pivot, lit
3092 //return an error, cannot both rotate and pivot
3093 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3094 break;
3095
3096 case 20:
3097 //lit + vflip
3098 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3099 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3100 break;
3101
3102 case 22:
3103 //Pivot, vflip, lit
3104 //return an error, cannot both rotate and pivot
3105 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3106 break;
3107
3108 case 24:
3109 //lit + h flip
3110 //return an error, cannot both rotate and H flip
3111 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3112 break;
3113
3114 case 26:
3115 //pivot + lit + hflip
3116 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3117 //return error cannot pivot, lit, and flip
3118 break;
3119
3120 case 28:
3121 //lit + vh flip
3122 //return an error, cannot both rotate and VH flip
3123 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3124 break;
3125
3126 case 32: //gouraud
3127 //Probably not wort supporting.
3128 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3129 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3130 break;
3131
3132 case 0:
3133 //no effect.
3134 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3135 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3136 break;
3137
3138 default:
3139 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3140
3141 }
3142 }
3143
3144 } //end if stretched, but not masked
3145 }
3146 else //not stretched
3147 {
3148
3149 if(masked) //if masked, but not stretched
3150 {
3151
3152 if ( rot == 0 ) //if not rotated
3153 {
3154 switch(mode)
3155 {
3156 case 1:
3157 //transparent
3158 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3159 draw_trans_sprite(bmp, subBmp, dx, dy);
3160 break;
3161
3162
3163 case 2:
3164 //pivot?
3165 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3166 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3167 //Pivoting requires two more args
3168 break;
3169
3170 case 3:
3171 //pivot + trans
3172 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3173 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3174 break;
3175
3176 case 4:
3177 //flip v
3178 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3179 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3180 break;
3181
3182 case 5:
3183 //trans + v flip
3184 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3185 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3186 break;
3187
3188 case 6:
3189 //pivot + v flip
3190 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3191 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3192 break;
3193
3194 case 8:
3195 //vlip h
3196 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3197 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3198 break;
3199
3200 case 9:
3201 //trans + h flip
3202 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3203 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3204 break;
3205
3206 case 10:
3207 //flip H and pivot
3208 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3209 //return error cannot pivot and h flip
3210 break;
3211
3212 case 12:
3213 //vh flip
3214 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3215 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3216 break;
3217
3218 case 13:
3219 //trans + vh flip
3220 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3221 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3222 break;
3223
3224 case 14:
3225 //pivot and vh flip
3226 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3227 //return error cannot both pivot and vh flip
3228 break;
3229
3230 case 16:
3231 //lit
3232 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3233 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3234 break;
3235
3236 case 18:
3237 //pivot, lit
3238 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3239 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3240 break;
3241
3242 case 20:
3243 //lit + v flip
3244 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3245 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3246 break;
3247
3248 case 22:
3249 //Pivot, vflip, lit
3250 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3251 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3252 break;
3253
3254 case 24:
3255 //lit + h flip
3256 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3257 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3258 break;
3259
3260 case 26:
3261 //pivot + lit + hflip
3262 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3263 //return error cannot pivot, lit, and flip
3264 break;
3265
3266 case 28:
3267 //lit + vh flip
3268 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3269 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3270 break;
3271
3272 case 32: //gouraud
3273 //Probably not wort supporting.
3274 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3275 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3276 break;
3277
3278 case 0:
3279 //no effect
3280 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3281 break;
3282
3283
3284 default:
3285 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3286
3287
3288 }
3289 } //end if not rotated
3290
3291 if ( rot != 0 ) //if rotated
3292 {
3293 switch(mode)
3294 {
3295 case 1:
3296 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //transparent
3297 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3298
3299 break;
3300
3301 case 2:
3302 //pivot?
3303 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3304 //return an error, cannot both rotate and pivot
3305 break;
3306
3307 case 3:
3308 //pivot + trans
3309 //return an error, cannot both rotate and pivot
3310 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3311 break;
3312
3313 case 4:
3314 //flip v
3315 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3316 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3317 break;
3318
3319 case 5:
3320 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
3321 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3322 break;
3323
3324 case 6:
3325 //pivot + v flip
3326 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3327 //return an error, cannot both rotate and pivot
3328 break;
3329
3330 case 8:
3331 //flip h
3332 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3333 //return an error, cannot both rotate and flip H
3334 break;
3335
3336 case 9:
3337 //trans + h flip
3338 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3339 //return an error, cannot rotate and flip a trans sprite
3340 break;
3341
3342 case 10:
3343 //flip H and pivot
3344 //return error cannot pivot and h flip
3345 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3346 break;
3347
3348 case 12:
3349 //vh flip
3350 //return an error, cannot rotate and VH flip a trans sprite
3351 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3352 break;
3353
3354 case 13:
3355 //trans + vh flip
3356 //return an error, cannot rotate and VH flip a trans sprite
3357 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3358 break;
3359
3360 case 14:
3361 //pivot and vh flip
3362 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3363 //return error cannot both pivot and vh flip
3364 break;
3365
3366 case 16:
3367 //lit
3368 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3369 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3370 break;
3371
3372 case 18:
3373 //pivot, lit
3374 //return an error, cannot both rotate and pivot
3375 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3376 break;
3377
3378 case 20:
3379 //lit + vflip
3380 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3381 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3382 break;
3383
3384 case 22:
3385 //Pivot, vflip, lit
3386 //return an error, cannot both rotate and pivot
3387 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3388 break;
3389
3390 case 24:
3391 //lit + h flip
3392 //return an error, cannot both rotate and H flip
3393 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3394 break;
3395
3396 case 26:
3397 //pivot + lit + hflip
3398 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3399 //return error cannot pivot, lit, and flip
3400 break;
3401
3402 case 28:
3403 //lit + vh flip
3404 //return an error, cannot both rotate and VH flip
3405 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3406 break;
3407
3408 case 32: //gouraud
3409 //Probably not wort supporting.
3410 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3411 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3412 break;
3413
3414 case 0:
3415 //no effect.
3416 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3417 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3418 break;
3419
3420 default:
3421 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3422
3423 }
3424 } //end rtated, masked
3425 } //end if masked
3426
3427 else //not masked, and not stretched; just blit
3428 {
3429
3430 if ( rot == 0 ) //if not rotated
3431 {
3432 switch(mode)
3433 {
3434 case 1:
3435 //transparent
3436 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3437 draw_trans_sprite(bmp, subBmp, dx, dy);
3438 break;
3439
3440
3441 case 2:
3442 //pivot?
3443 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3444 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3445 //Pivoting requires two more args
3446 break;
3447
3448 case 3:
3449 //pivot + trans
3450 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3451 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3452 break;
3453
3454 case 4:
3455 //flip v
3456 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3457 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3458 break;
3459
3460 case 5:
3461 //trans + v flip
3462 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3463 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3464 break;
3465
3466 case 6:
3467 //pivot + v flip
3468 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3469 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3470 break;
3471
3472 case 8:
3473 //vlip h
3474 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3475 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3476 break;
3477
3478 case 9:
3479 //trans + h flip
3480 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3481 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3482 break;
3483
3484 case 10:
3485 //flip H and pivot
3486 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3487 //return error cannot pivot and h flip
3488 break;
3489
3490 case 12:
3491 //vh flip
3492 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3493 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3494 break;
3495
3496 case 13:
3497 //trans + vh flip
3498 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3499 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3500 break;
3501
3502 case 14:
3503 //pivot and vh flip
3504 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3505 //return error cannot both pivot and vh flip
3506 break;
3507
3508 case 16:
3509 //lit
3510 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3511 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3512 break;
3513
3514 case 18:
3515 //pivot, lit
3516 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3517 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3518 break;
3519
3520 case 20:
3521 //lit + v flip
3522 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3523 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3524 break;
3525
3526 case 22:
3527 //Pivot, vflip, lit
3528 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3529 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3530 break;
3531
3532 case 24:
3533 //lit + h flip
3534 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3535 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3536 break;
3537
3538 case 26:
3539 //pivot + lit + hflip
3540 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3541 //return error cannot pivot, lit, and flip
3542 break;
3543
3544 case 28:
3545 //lit + vh flip
3546 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3547 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3548 break;
3549
3550 case 32: //gouraud
3551 //Probably not wort supporting.
3552 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3553 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3554 break;
3555
3556 case 0:
3557 //no effect
3558 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3559 break;
3560
3561
3562 default:
3563 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3564
3565
3566 }
3567 } //end if not rotated
3568
3569 if ( rot != 0 ) //if rotated
3570 {
3571 switch(mode)
3572 {
3573 case 1:
3574 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);//transparent
3575 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3576
3577 break;
3578
3579 case 2:
3580 //pivot?
3581 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3582 //return an error, cannot both rotate and pivot
3583 break;
3584
3585 case 3:
3586 //pivot + trans
3587 //return an error, cannot both rotate and pivot
3588 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3589 break;
3590
3591 case 4:
3592 //flip v
3593 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3594 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3595 break;
3596
3597 case 5:
3598 //trans + v flip
3599 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3600 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3601 break;
3602
3603 case 6:
3604 //pivot + v flip
3605 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3606 //return an error, cannot both rotate and pivot
3607 break;
3608
3609 case 8:
3610 //flip h
3611 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3612 //return an error, cannot both rotate and flip H
3613 break;
3614
3615 case 9:
3616 //trans + h flip
3617 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3618 //return an error, cannot rotate and flip a trans sprite
3619 break;
3620
3621 case 10:
3622 //flip H and pivot
3623 //return error cannot pivot and h flip
3624 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3625 break;
3626
3627 case 12:
3628 //vh flip
3629 //return an error, cannot rotate and VH flip a trans sprite
3630 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3631 break;
3632
3633 case 13:
3634 //trans + vh flip
3635 //return an error, cannot rotate and VH flip a trans sprite
3636 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3637 break;
3638
3639 case 14:
3640 //pivot and vh flip
3641 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3642 //return error cannot both pivot and vh flip
3643 break;
3644
3645 case 16:
3646 //lit
3647 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3648 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3649 break;
3650
3651 case 18:
3652 //pivot, lit
3653 //return an error, cannot both rotate and pivot
3654 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3655 break;
3656
3657 case 20:
3658 //lit + vflip
3659 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3660 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3661 break;
3662
3663 case 22:
3664 //Pivot, vflip, lit
3665 //return an error, cannot both rotate and pivot
3666 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3667 break;
3668
3669 case 24:
3670 //lit + h flip
3671 //return an error, cannot both rotate and H flip
3672 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3673 break;
3674
3675 case 26:
3676 //pivot + lit + hflip
3677 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3678 //return error cannot pivot, lit, and flip
3679 break;
3680
3681 case 28:
3682 //lit + vh flip
3683 //return an error, cannot both rotate and VH flip
3684 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3685 break;
3686
3687 case 32: //gouraud
3688 //Probably not wort supporting.
3689 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3690 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3691 break;
3692
3693 case 0:
3694 //no effect.
3695 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3696 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3697 break;
3698
3699 default:
3700 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3701
3702 }
3703 } //end if rotated
3704 } //end if not masked
3705 } //end if not stretched
3706
3707 //cleanup
3708 if(subBmp)
3709 {
3710 script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
3711 }
3712 }
3713
3714
3715 void do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3716 {
3717 //sdci[1]=layer
3718 //sdci[2]=pos[12]
3719 //sdci[3]=uv[8]
3720 //sdci[4]=color[4]
3721 //sdci[5]=size[2]
3722 //sdci[6]=flip
3723 //sdci[7]=tile/combo
3724 //sdci[8]=polytype
3725
3726 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3727
3728 if(!v_ptr)
3729 {
3730 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
3731 return;
3732 }
3733
3734 std::vector<int32_t> &v = *v_ptr;
3735
3736 if(v.empty())
3737 return;
3738
3739 int32_t* pos = &v[0];
3740 int32_t* uv = &v[12];
3741 int32_t* col = &v[20];
3742 int32_t* size = &v[24];
3743
3744 int32_t w = size[0]; //magic numerical constants... yuck.
3745 int32_t h = size[1];
3746 int32_t flip = (sdci[6]/10000)&3;
3747 int32_t tile = sdci[7]/10000;
3748 int32_t polytype = sdci[8]/10000;
3749
3750 polytype = vbound(polytype, 0, 14);
3751
3752 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3753 {
3754 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3755 return; //non power of two error
3756 }
3757
3758 int32_t tex_width = w*16;
3759 int32_t tex_height = h*16;
3760
3761 bool mustDestroyBmp = false;
3762 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3763
3764 if(!tex)
3765 {
3766 mustDestroyBmp = true;
3767 tex = create_bitmap_ex(8, tex_width, tex_height);
3768 clear_bitmap(tex);
3769 }
3770
3771 if(tile > 0) // TILE
3772 {
3773 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3774 }
3775 else // COMBO
3776 {
3777 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3778 const int32_t tiletodraw = combo_tile(c, 0, 0);
3779 flip = flip ^ c.flip;
3780
3781 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3782 }
3783
3784 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3785 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3786 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3787 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
3788
3789 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
3790
3791 if(mustDestroyBmp)
3792 destroy_bitmap(tex);
3793
3794 }
3795
3796
3797
3798 void do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3799 {
3800 //sdci[1]=layer
3801 //sdci[2]=pos[9]
3802 //sdci[3]=uv[6]
3803 //sdci[4]=color[3]
3804 //sdci[5]=size[2]
3805 //sdci[6]=flip
3806 //sdci[7]=tile/combo
3807 //sdci[8]=polytype
3808
3809 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3810
3811 if(!v_ptr)
3812 {
3813 al_trace("Triange3d: Vector pointer is null! Internal error. \n");
3814 return;
3815 }
3816
3817 std::vector<int32_t> &v = *v_ptr;
3818
3819 if(v.empty())
3820 return;
3821
3822 int32_t* pos = &v[0];
3823 int32_t* uv = &v[9];
3824 int32_t* col = &v[15];
3825 int32_t* size = &v[18];
3826
3827 int32_t w = size[0]; //magic numerical constants... yuck.
3828 int32_t h = size[1];
3829 int32_t flip = (sdci[6]/10000)&3;
3830 int32_t tile = sdci[7]/10000;
3831 int32_t polytype = sdci[8]/10000;
3832
3833 polytype = vbound(polytype, 0, 14);
3834
3835 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3836 {
3837 Z_message("Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3838 return; //non power of two error
3839 }
3840
3841 int32_t tex_width = w*16;
3842 int32_t tex_height = h*16;
3843
3844 bool mustDestroyBmp = false;
3845 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3846
3847 if(!tex)
3848 {
3849 mustDestroyBmp = true;
3850 tex = create_bitmap_ex(8, tex_width, tex_height);
3851 clear_bitmap(tex);
3852 }
3853
3854 if(tile > 0) // TILE
3855 {
3856 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3857 }
3858 else // COMBO
3859 {
3860 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3861 const int32_t tiletodraw = combo_tile(c, 0, 0);
3862 flip = flip ^ c.flip;
3863
3864 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3865 }
3866
3867 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3868 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3869 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3870
3871 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
3872
3873 if(mustDestroyBmp)
3874 destroy_bitmap(tex);
3875
3876 }
3877
3878 7971 void bmp_do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3879 {
3880 //Z_scripterrlog("rect sdci[13] is: %d\n", sdci[13]);
3881 //sdci[1]=layer
3882 //sdci[2]=x
3883 //sdci[3]=y
3884 //sdci[4]=x2
3885 //sdci[5]=y2
3886 //sdci[6]=color
3887 //sdci[7]=scale factor
3888 //sdci[8]=rotation anchor x
3889 //sdci[9]=rotation anchor y
3890 //sdci[10]=rotation angle
3891 //sdci[11]=fill
3892 //sdci[12]=opacity
3893 //sdci[17] Bitmap Pointer
3894
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7]==0) //scale
3895 {
3896 return;
3897 }
3898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7971 times.
7971 if ( sdci[17] <= 0 )
3899 {
3900 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
3901 return;
3902 }
3903 7971 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
3904
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if ( refbmp == NULL ) return;
3905
3906
2/4
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7971 times.
7971 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
3907
3908 7971 int32_t x1=sdci[2]/10000;
3909 7971 int32_t y1=sdci[3]/10000;
3910 7971 int32_t x2=sdci[4]/10000;
3911 7971 int32_t y2=sdci[5]/10000;
3912
3913
3914
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(x1>x2)
3915 {
3916 4 zc_swap(x1,x2);
3917 4 }
3918
3919
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(y1>y2)
3920 {
3921 4 zc_swap(y1,y2);
3922 4 }
3923
3924
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7] != 10000)
3925 {
3926 int32_t w=x2-x1+1;
3927 int32_t h=y2-y1+1;
3928 int32_t w2=(w*sdci[7])/10000;
3929 int32_t h2=(h*sdci[7])/10000;
3930 x1=x1-((w2-w)/2);
3931 x2=x2+((w2-w)/2);
3932 y1=y1-((h2-h)/2);
3933 y2=y2+((h2-h)/2);
3934 }
3935
3936 7971 int32_t color=sdci[6]/10000;
3937
3938
2/2
✓ Branch 0 taken 7843 times.
✓ Branch 1 taken 128 times.
7971 if(sdci[12]/10000<=127) //translucent
3939 {
3940 128 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
3941 128 }
3942
3943
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 7875 times.
7971 if(sdci[10]==0) //no rotation
3944 {
3945
2/2
✓ Branch 0 taken 7863 times.
✓ Branch 1 taken 12 times.
7875 if(sdci[11]) //filled
3946 {
3947 7863 rectfill(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3948 7863 }
3949 else //outline
3950 {
3951 12 rect(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3952 }
3953 7875 }
3954 else //rotate
3955 {
3956 int32_t xy[16];
3957 96 int32_t rx=sdci[8]/10000;
3958 96 int32_t ry=sdci[9]/10000;
3959 96 fixed ra1=itofix(sdci[10]%10000)/10000;
3960 96 fixed ra2=itofix(sdci[10]/10000);
3961 96 fixed ra=ra1+ra2;
3962 96 ra = (ra/360)*256;
3963
3964 96 fixed fcosa = fixcos(ra);
3965 96 fixed fsina = fixsin(ra);
3966
3967 96 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
3968 96 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
3969 96 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
3970 96 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
3971 96 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
3972 96 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
3973 96 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
3974 96 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
3975 96 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
3976 96 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
3977 96 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
3978 96 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
3979 96 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
3980 96 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
3981 96 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
3982 96 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
3983
3984
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(sdci[11]) //filled
3985 {
3986 96 polygon(refbmp, 4, xy, color);
3987 96 }
3988 else //outline
3989 {
3990 line(refbmp, xy[0], xy[1], xy[10], xy[11], color);
3991 line(refbmp, xy[2], xy[3], xy[12], xy[13], color);
3992 line(refbmp, xy[4], xy[5], xy[14], xy[15], color);
3993 line(refbmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
3994 }
3995 }
3996
3997 7971 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
3998 7971 }
3999
4000 void bmp_do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4001 {
4002 //sdci[1]=layer
4003 //sdci[2]=x
4004 //sdci[3]=y
4005 //sdci[4]=tile
4006 //sdci[5]=cset
4007 //sdci[6]=width
4008 //sdci[7]=height
4009 //sdci[8]=overlay
4010 //sdci[9]=opacity
4011
4012 if ( sdci[17] <= 0 )
4013 {
4014 Z_scripterrlog("bitmap->DrawFrame() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4015 return;
4016 }
4017 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4018 if ( refbmp == NULL ) return;
4019
4020 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4021
4022 int32_t x=sdci[2]/10000;
4023 int32_t y=sdci[3]/10000;
4024
4025 int32_t tile=sdci[4]/10000;
4026 int32_t cs=sdci[5]/10000;
4027 int32_t w=sdci[6]/10000;
4028 int32_t h=sdci[7]/10000;
4029 bool overlay=sdci[8];
4030 bool trans=(sdci[9]/10000<=127);
4031
4032 frame2x2(refbmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
4033 }
4034
4035
4036 148823 void bmp_do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4037 {
4038 //sdci[1]=layer
4039 //sdci[2]=x
4040 //sdci[3]=y
4041 //sdci[4]=radius
4042 //sdci[5]=color
4043 //sdci[6]=scale factor
4044 //sdci[7]=rotation anchor x
4045 //sdci[8]=rotation anchor y
4046 //sdci[9]=rotation angle
4047 //sdci[10]=fill
4048 //sdci[11]=opacity
4049 //sdci[17] Bitmap Pointer
4050
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6]==0) //scale
4051 {
4052 return;
4053 }
4054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
148823 if ( sdci[17] <= 0 )
4055 {
4056 Z_scripterrlog("bitmap->Circle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4057 return;
4058 }
4059 148823 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4060
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if ( refbmp == NULL ) return;
4061
4062
2/4
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 148823 times.
148823 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4063
4064 148823 int32_t x1=sdci[2]/10000;
4065 148823 int32_t y1=sdci[3]/10000;
4066 148823 qword r=sdci[4];
4067
4068
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6] != 10000)
4069 {
4070 r*=sdci[6];
4071 r/=10000;
4072 }
4073
4074 148823 r/=10000;
4075 148823 int32_t color=sdci[5]/10000;
4076
4077
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[11]/10000<=127) //translucent
4078 {
4079 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4080 }
4081
4082
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
148823 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
4083 {
4084 int32_t xy[2];
4085 int32_t rx=sdci[7]/10000;
4086 int32_t ry=sdci[8]/10000;
4087 fixed ra1=itofix(sdci[9]%10000)/10000;
4088 fixed ra2=itofix(sdci[9]/10000);
4089 fixed ra=ra1+ra2;
4090 ra = (ra/360)*256;
4091
4092 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4093 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4094 x1=xy[0];
4095 y1=xy[1];
4096 }
4097
4098
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[10]) //filled
4099 {
4100 148823 circlefill(refbmp, x1+xoffset, y1+yoffset, r, color);
4101 148823 }
4102 else //outline
4103 {
4104 circle(refbmp, x1+xoffset, y1+yoffset, r, color);
4105 }
4106
4107 148823 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4108 148823 }
4109
4110
4111 void bmp_do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4112 {
4113 //sdci[1]=layer
4114 //sdci[2]=x
4115 //sdci[3]=y
4116 //sdci[4]=radius
4117 //sdci[5]=start angle
4118 //sdci[6]=end angle
4119 //sdci[7]=color
4120 //sdci[8]=scale factor
4121 //sdci[9]=rotation anchor x
4122 //sdci[10]=rotation anchor y
4123 //sdci[11]=rotation angle
4124 //sdci[12]=closed
4125 //sdci[13]=fill
4126 //sdci[14]=opacity
4127 //sdci[17] Bitmap Pointer
4128
4129 if(sdci[8]==0) //scale
4130 {
4131 return;
4132 }
4133 if ( sdci[17] <= 0 )
4134 {
4135 Z_scripterrlog("bitmap->Arc() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4136 return;
4137 }
4138 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4139 if ( refbmp == NULL ) return;
4140
4141 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4142
4143 int32_t cx=sdci[2]/10000;
4144 int32_t cy=sdci[3]/10000;
4145 qword r=sdci[4];
4146
4147 if(sdci[8] != 10000)
4148 {
4149 r*=sdci[8];
4150 r/=10000;
4151 }
4152
4153 r/=10000;
4154
4155 int32_t color=sdci[7]/10000;
4156
4157 fixed ra1=itofix(sdci[11]%10000)/10000;
4158 fixed ra2=itofix(sdci[11]/10000);
4159 fixed ra=ra1+ra2;
4160 ra = (ra/360)*256;
4161
4162
4163 fixed a1=itofix(sdci[5]%10000)/10000;
4164 fixed a2=itofix(sdci[5]/10000);
4165 fixed sa=a1+a2;
4166 sa = (sa/360)*256;
4167
4168 a1=itofix(sdci[6]%10000)/10000;
4169 a2=itofix(sdci[6]/10000);
4170 fixed ea=a1+a2;
4171 ea = (ea/360)*256;
4172
4173 if(sdci[11]!=0) //rotation
4174 {
4175 int32_t rx=sdci[9]/10000;
4176 int32_t ry=sdci[10]/10000;
4177
4178 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
4179 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
4180 ea-=ra;
4181 sa-=ra;
4182 }
4183
4184 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
4185 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
4186
4187 if(sdci[12]) //closed
4188 {
4189 if(sdci[13]) //filled
4190 {
4191 clear_bitmap(prim_bmp);
4192 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4193 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4194 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4195 int fillx = zc_max(0,fx)+xoffset;
4196 int filly = zc_max(0,fy)+yoffset;
4197 zprint2("bitmap->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
4198 floodfill(prim_bmp, fillx, filly, color);
4199
4200 if(sdci[14]/10000<=127) //translucent
4201 {
4202 draw_trans_sprite(refbmp, prim_bmp, 0,0);
4203 }
4204 else
4205 {
4206 draw_sprite(refbmp, prim_bmp, 0,0);
4207 }
4208 }
4209 else
4210 {
4211 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4212 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4213 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4214 }
4215 }
4216 else
4217 {
4218 if(sdci[14]/10000<=127) //translucent
4219 {
4220 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4221 }
4222
4223 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4224 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4225 }
4226 }
4227
4228
4229 502 void bmp_do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4230 {
4231 //sdci[1]=layer
4232 //sdci[2]=x
4233 //sdci[3]=y
4234 //sdci[4]=radiusx
4235 //sdci[5]=radiusy
4236 //sdci[6]=color
4237 //sdci[7]=scale factor
4238 //sdci[8]=rotation anchor x
4239 //sdci[9]=rotation anchor y
4240 //sdci[10]=rotation angle
4241 //sdci[11]=fill
4242 //sdci[12]=opacity
4243 //sdci[17] Bitmap Pointer
4244
4245
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if(sdci[7]==0) //scale
4246 {
4247 return;
4248 }
4249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 502 times.
502 if ( sdci[17] <= 0 )
4250 {
4251 Z_scripterrlog("bitmap->Ellipse() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4252 return;
4253 }
4254 502 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4255
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if ( refbmp == NULL ) return;
4256
4257 502 int32_t x1=sdci[2]/10000;
4258 502 int32_t y1=sdci[3]/10000;
4259 502 int32_t radx=sdci[4]/10000;
4260 502 radx*=sdci[7]/10000;
4261 502 int32_t rady=sdci[5]/10000;
4262 502 rady*=sdci[7]/10000;
4263 502 int32_t color=sdci[6]/10000;
4264 502 float rotation = sdci[10]/10000;
4265
4266 502 int32_t rx=sdci[8]/10000;
4267 502 int32_t ry=sdci[9]/10000;
4268 502 fixed ra1=itofix(sdci[10]%10000)/10000;
4269 502 fixed ra2=itofix(sdci[10]/10000);
4270 502 fixed ra=ra1+ra2;
4271 502 ra = (ra/360)*256;
4272
4273
2/4
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 502 times.
✗ Branch 3 not taken.
502 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4274
4275 int32_t xy[2];
4276 502 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4277 502 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4278 502 x1=xy[0];
4279 502 y1=xy[1];
4280
4281
6/8
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 494 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 494 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 494 times.
502 if(radx<1||rady<1||radx>255||rady>255) return;
4282
4283 494 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
4284
4285
2/4
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 494 times.
494 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4286
4287
1/2
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
494 if(sdci[11]) //filled
4288 {
4289
4290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 494 times.
494 if(sdci[12]/10000<128) //translucent
4291 {
4292 clear_bitmap(prim_bmp);
4293 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4294 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4295 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4296 }
4297 else // no opacity
4298 {
4299
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4300 494 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4301 }
4302 494 }
4303 else //not filled
4304 {
4305 if(sdci[12]/10000<128) //translucent
4306 {
4307 clear_bitmap(prim_bmp);
4308 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4309 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4310 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4311 }
4312 else // no opacity
4313 {
4314 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4315 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4316 }
4317 }
4318
4319 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
4320 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
4321 // the ellipse, but it shouldn't be used anyway.
4322
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 if(color==0)
4323 {
4324 // This is very slow, so check the smallest possible square
4325
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
4326
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
4327
4328
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 60 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4430 times.
✓ Branch 7 taken 62 times.
4492 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
4329
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 4430 times.
✓ Branch 2 taken 1086 times.
✓ Branch 3 taken 3344 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1086 times.
✓ Branch 6 taken 467774 times.
✓ Branch 7 taken 4430 times.
472204 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
4330
2/2
✓ Branch 0 taken 238992 times.
✓ Branch 1 taken 228782 times.
696556 if(getpixel(refbmp, x, y)==255)
4331 233212 putpixel(refbmp, x, y, 0);
4332 62 }
4333
4334 494 script_drawing_commands.ReleaseSubBitmap(bitty);
4335 502 }
4336
4337
4338 144 void bmp_do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4339 {
4340 //sdci[1]=layer
4341 //sdci[2]=x
4342 //sdci[3]=y
4343 //sdci[4]=x2
4344 //sdci[5]=y2
4345 //sdci[6]=color
4346 //sdci[7]=scale factor
4347 //sdci[8]=rotation anchor x
4348 //sdci[9]=rotation anchor y
4349 //sdci[10]=rotation angle
4350 //sdci[11]=opacity
4351 //sdci[17] Bitmap Pointer
4352
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7]==0) //scale
4353 {
4354 return;
4355 }
4356
4357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 144 times.
144 if ( sdci[17] <= 0 )
4358 {
4359 Z_scripterrlog("bitmap->Line() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4360 return;
4361 }
4362
4363 144 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4364
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if ( refbmp == NULL ) return;
4365
4366 144 int32_t x1=sdci[2]/10000;
4367 144 int32_t y1=sdci[3]/10000;
4368 144 int32_t x2=sdci[4]/10000;
4369 144 int32_t y2=sdci[5]/10000;
4370
4371
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7] != 10000)
4372 {
4373 int32_t w=x2-x1+1;
4374 int32_t h=y2-y1+1;
4375 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
4376 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
4377 x1=x1-((w2-w)/2);
4378 x2=x2+((w2-w)/2);
4379 y1=y1-((h2-h)/2);
4380 y2=y2+((h2-h)/2);
4381 }
4382
4383 144 int32_t color=sdci[6]/10000;
4384
4385
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
144 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4386
4387
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[11]/10000<=127) //translucent
4388 {
4389 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4390 }
4391
4392
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[10]!=0) //rotation
4393 {
4394 int32_t xy[4];
4395 int32_t rx=sdci[8]/10000;
4396 int32_t ry=sdci[9]/10000;
4397 fixed ra1=itofix(sdci[10]%10000)/10000;
4398 fixed ra2=itofix(sdci[10]/10000);
4399 fixed ra=ra1+ra2;
4400
4401 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4402 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4403 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
4404 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
4405 x1=xy[0];
4406 y1=xy[1];
4407 x2=xy[2];
4408 y2=xy[3];
4409 }
4410
4411 144 line(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4412 144 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4413 144 }
4414
4415
4416 void bmp_do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4417 {
4418 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
4419 //sdci[17] Bitmap Pointer
4420
4421 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
4422 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
4423 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
4424 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
4425 };
4426
4427 if(sdci[11]/10000 < 128) //translucent
4428 {
4429 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4430 }
4431
4432 if ( sdci[17] <= 0 )
4433 {
4434 Z_scripterrlog("bitmap->Spline() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4435 return;
4436 }
4437
4438 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4439 if ( refbmp == NULL ) return;
4440
4441 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4442
4443 spline(refbmp, points, sdci[10]/10000);
4444
4445 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4446 }
4447
4448
4449 80910 void bmp_do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4450 {
4451 //sdci[1]=layer
4452 //sdci[2]=x
4453 //sdci[3]=y
4454 //sdci[4]=color
4455 //sdci[5]=rotation anchor x
4456 //sdci[6]=rotation anchor y
4457 //sdci[7]=rotation angle
4458 //sdci[8]=opacity
4459 //sdci[17] Bitmap Pointer
4460 80910 int32_t x1=sdci[2]/10000;
4461 80910 int32_t y1=sdci[3]/10000;
4462 80910 int32_t color=sdci[4]/10000;
4463
4464
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if(sdci[8]/10000<=127) //translucent
4465 {
4466 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4467 }
4468
4469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if ( sdci[17] <= 0 )
4470 {
4471 Z_scripterrlog("bitmap->PutPixel() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4472 return;
4473 }
4474
4475 80910 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4476
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if ( refbmp == NULL ) return;
4477
4478
2/4
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80910 times.
✗ Branch 3 not taken.
80910 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4479
4480
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if(sdci[7]!=0) //rotation
4481 {
4482 int32_t xy[2];
4483 int32_t rx=sdci[5]/10000;
4484 int32_t ry=sdci[6]/10000;
4485 fixed ra1=itofix(sdci[7]%10000)/10000;
4486 fixed ra2=itofix(sdci[7]/10000);
4487 fixed ra=ra1+ra2;
4488
4489 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4490 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4491 x1=xy[0];
4492 y1=xy[1];
4493 }
4494
4495 80910 putpixel(refbmp, x1+xoffset, y1+yoffset, color);
4496 80910 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4497 80910 }
4498
4499
4500 59816 void bmp_do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4501 {
4502 //sdci[1]=layer
4503 //sdci[2]=x
4504 //sdci[3]=y
4505 //sdci[4]=tile
4506 //sdci[5]=tile width
4507 //sdci[6]=tile height
4508 //sdci[7]=color (cset)
4509 //sdci[8]=scale x
4510 //sdci[9]=scale y
4511 //sdci[10]=rotation anchor x
4512 //sdci[11]=rotation anchor y
4513 //sdci[12]=rotation angle
4514 //sdci[13]=flip
4515 //sdci[14]=transparency
4516 //sdci[15]=opacity
4517 //sdci[17] Bitmap Pointer
4518
4519 59816 int32_t w = sdci[5]/10000;
4520 59816 int32_t h = sdci[6]/10000;
4521
4522
4/8
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59816 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 59816 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 59816 times.
59816 if(w < 1 || h < 1 || h > 20 || w > 20)
4523 {
4524 return;
4525 }
4526
4527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( sdci[17] <= 0 )
4528 {
4529 Z_scripterrlog("bitmap->DrawTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4530 return;
4531 }
4532
4533 59816 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( refbmp == NULL ) return;
4535
4536 59816 int32_t xscale=sdci[8]/10000;
4537 59816 int32_t yscale=sdci[9]/10000;
4538 59816 int32_t rx = sdci[10]/10000;
4539 59816 int32_t ry = sdci[11]/10000;
4540 59816 float rotation=sdci[12]/10000;
4541 59816 int32_t flip=(sdci[13]/10000)&3;
4542 59816 bool transparency=sdci[14]!=0;
4543 59816 int32_t opacity=sdci[15]/10000;
4544 59816 int32_t color=sdci[7]/10000;
4545
4546 59816 int32_t x1=sdci[2]/10000;
4547 59816 int32_t y1=sdci[3]/10000;
4548
4549
4550 //don't scale if it's not safe to do so
4551 59816 bool canscale = true;
4552
4553
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if(xscale==0||yscale==0)
4554 {
4555 return;
4556 }
4557
4558
3/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 906 times.
✗ Branch 3 not taken.
59816 if(xscale<0||yscale<0)
4559 58910 canscale = false; //default size
4560
4561
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4562
4563
4/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 4608 times.
✓ Branch 3 taken 54302 times.
59816 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4564 {
4565 5514 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
4566
4567
1/2
✓ Branch 0 taken 5514 times.
✗ Branch 1 not taken.
5514 if(transparency) //transparency
4568 {
4569 5514 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4570 5514 }
4571 else //no transparency
4572 {
4573 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4574 }
4575
4576
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 906 times.
5514 if(rotation != 0)
4577 {
4578 //low negative values indicate no anchor-point rotation
4579
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4608 if(rx>-777||ry>-777)
4580 {
4581 int32_t xy[2];
4582 4608 fixed ra1=itofix(sdci[12]%10000)/10000;
4583 4608 fixed ra2=itofix(sdci[12]/10000);
4584 4608 fixed ra=ra1+ra2;
4585 4608 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4586 4608 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4587 4608 x1=xy[0];
4588 4608 y1=xy[1];
4589 4608 }
4590
4591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(canscale) //scale first
4592 {
4593 //damnit all, .. fixme.
4594 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4595 clear_bitmap(tempbit);
4596
4597 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4598
4599 if(opacity < 128)
4600 {
4601 clear_bitmap(prim_bmp);
4602 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4603 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
4604 }
4605 else
4606 {
4607 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4608 }
4609
4610 destroy_bitmap(tempbit);
4611 }
4612 else //no scale
4613 {
4614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(opacity < 128)
4615 {
4616 clear_bitmap(prim_bmp);
4617 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4618 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4619 }
4620 else
4621 {
4622 4608 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4623 }
4624 }
4625 4608 }
4626 else //scale only
4627 {
4628
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if(canscale)
4629 {
4630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(opacity<128)
4631 {
4632 clear_bitmap(prim_bmp);
4633 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4634 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4635 }
4636 else
4637 {
4638 906 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4639 }
4640 906 }
4641 else //error -do not scale
4642 {
4643 if(opacity<128)
4644 {
4645 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4646 }
4647 else
4648 {
4649 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4650 }
4651 }
4652 }
4653
4654 5514 script_drawing_commands.ReleaseSubBitmap(pbitty);
4655
4656 5514 }
4657 else // no scale or rotation
4658 {
4659
2/2
✓ Branch 0 taken 45964 times.
✓ Branch 1 taken 8338 times.
54302 if(transparency)
4660 {
4661
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45964 times.
45964 if(opacity<=127)
4662 TileHelper::OverTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4663 else
4664 45964 TileHelper::OverTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4665 45964 }
4666 else
4667 {
4668
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8338 times.
8338 if(opacity<=127)
4669 TileHelper::PutTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4670 else
4671 8338 TileHelper::OldPutTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4672 }
4673 }
4674 59816 }
4675
4676 void bmp_do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4677 {
4678 //sdci[1]=layer
4679 //sdci[2]=x
4680 //sdci[3]=y
4681 //sdci[4]=tile
4682 //sdci[5]=tile width
4683 //sdci[6]=tile height
4684 //sdci[7]=flip
4685 //sdci[17] Bitmap Pointer
4686
4687 int32_t w = sdci[5]/10000;
4688 int32_t h = sdci[6]/10000;
4689
4690 if(w < 1 || h < 1 || h > 20 || w > 20)
4691 {
4692 return;
4693 }
4694
4695 if ( sdci[17] <= 0 )
4696 {
4697 Z_scripterrlog("bitmap->DrawTileCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4698 return;
4699 }
4700
4701 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4702 if ( refbmp == NULL ) return;
4703
4704 int32_t flip=(sdci[7]/10000)&3;
4705
4706 int32_t x1=sdci[2]/10000;
4707 int32_t y1=sdci[3]/10000;
4708
4709 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4710
4711 TileHelper::OverTileCloaked(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
4712 }
4713
4714
4715 824 void bmp_do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4716 {
4717 //sdci[1]=layer
4718 //sdci[2]=x
4719 //sdci[3]=y
4720 //sdci[4]=combo
4721 //sdci[5]=tile width
4722 //sdci[6]=tile height
4723 //sdci[7]=color (cset)
4724 //sdci[8]=scale x
4725 //sdci[9]=scale y
4726 //sdci[10]=rotation anchor x
4727 //sdci[11]=rotation anchor y
4728 //sdci[12]=rotation angle
4729 //sdci[13]=frame
4730 //sdci[14]=flip
4731 //sdci[15]=transparency
4732 //sdci[16]=opacity
4733 //sdci[17] Bitmap Pointer
4734 824 int32_t w = sdci[5]/10000;
4735 824 int32_t h = sdci[6]/10000;
4736
4737
4/8
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 824 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 824 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 824 times.
824 if(w<1||h<1||h>20||w>20)
4738 {
4739 return;
4740 }
4741
4742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if ( sdci[17] <= 0 )
4743 {
4744 Z_scripterrlog("bitmap->DrawCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4745 return;
4746 }
4747
4748 824 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4749
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if ( refbmp == NULL ) return;
4750 824 int32_t cmb = (sdci[4]/10000);
4751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if((unsigned)cmb >= MAXCOMBOS)
4752 {
4753 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4754 return;
4755 }
4756
4757 824 int32_t xscale=sdci[8]/10000;
4758 824 int32_t yscale=sdci[9]/10000;
4759 824 int32_t rx = sdci[10]/10000; //these work now
4760 824 int32_t ry = sdci[11]/10000; //these work now
4761 824 float rotation=sdci[12]/10000;
4762
4763 824 bool transparency=sdci[15]!=0;
4764 824 int32_t opacity=sdci[16]/10000;
4765 824 int32_t color=sdci[7]/10000;
4766 824 int32_t x1=sdci[2]/10000;
4767 824 int32_t y1=sdci[3]/10000;
4768
4769 824 const newcombo & c = combobuf[cmb];
4770 824 int32_t tiletodraw = combo_tile(c, x1, y1);
4771 824 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
4772 824 int32_t skiprows=c.skipanimy;
4773
4774
4775 //don't scale if it's not safe to do so
4776 824 bool canscale = true;
4777
4778
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if(xscale==0||yscale==0)
4779 {
4780 return;
4781 }
4782
4783
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
824 if(xscale<0||yscale<0)
4784 824 canscale = false; //default size
4785
4786
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4787
4788
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4789 {
4790 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
4791
4792 if(transparency)
4793 {
4794 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4795 }
4796 else //no transparency
4797 {
4798 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4799 }
4800
4801 if(rotation != 0) // rotate
4802 {
4803 //fixed point sucks ;0
4804 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
4805 {
4806 int32_t xy[2];
4807 fixed ra1=itofix(sdci[12]%10000)/10000;
4808 fixed ra2=itofix(sdci[12]/10000);
4809 fixed ra=ra1+ra2;
4810 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4811 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4812 x1=xy[0];
4813 y1=xy[1];
4814 }
4815
4816 if(canscale) //scale first
4817 {
4818 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4819 clear_bitmap(tempbit);
4820
4821 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4822
4823 if(opacity < 128)
4824 {
4825 clear_bitmap(prim_bmp);
4826 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4827 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4828 }
4829 else
4830 {
4831 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4832 }
4833
4834 destroy_bitmap(tempbit);
4835 }
4836 else //no scale
4837 {
4838 if(opacity < 128)
4839 {
4840 clear_bitmap(prim_bmp);
4841 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4842 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4843 }
4844 else
4845 {
4846 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4847 }
4848 }
4849 }
4850 else //scale only
4851 {
4852 if(canscale)
4853 {
4854 if(opacity<128)
4855 {
4856 clear_bitmap(prim_bmp);
4857 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4858 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4859 }
4860 else
4861 {
4862 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4863 }
4864 }
4865 else //error -do not scale
4866 {
4867 if(opacity<128)
4868 {
4869 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4870 }
4871 else
4872 {
4873 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4874 }
4875 }
4876 }
4877
4878 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
4879 }
4880 else // no scale or rotation
4881 {
4882
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if(transparency)
4883 {
4884
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if(opacity<=127)
4885 TileHelper::OverTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4886 else
4887 824 TileHelper::OverTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4888 824 }
4889 else
4890 {
4891 if(opacity<=127)
4892 TileHelper::PutTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4893 else
4894 TileHelper::OldPutTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4895 }
4896 }
4897 824 }
4898
4899
4900 void bmp_do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4901 {
4902 //sdci[1]=layer
4903 //sdci[2]=x
4904 //sdci[3]=y
4905 //sdci[4]=combo
4906 //sdci[5]=tile width
4907 //sdci[6]=tile height
4908 //sdci[7]=flip
4909 //sdci[17] Bitmap Pointer
4910
4911 int32_t w = sdci[5]/10000;
4912 int32_t h = sdci[6]/10000;
4913
4914 if(w<1||h<1||h>20||w>20)
4915 {
4916 return;
4917 }
4918
4919 if ( sdci[17] <= 0 )
4920 {
4921 Z_scripterrlog("bitmap->DrawComboCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4922 return;
4923 }
4924
4925 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4926 if ( refbmp == NULL ) return;
4927 int32_t cmb = (sdci[4]/10000);
4928 if((unsigned)cmb >= MAXCOMBOS)
4929 {
4930 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4931 return;
4932 }
4933
4934 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4935
4936 int32_t x1=sdci[2]/10000;
4937 int32_t y1=sdci[3]/10000;
4938
4939 const newcombo & c = combobuf[cmb];
4940 int32_t tiletodraw = combo_tile(c, x1, y1);
4941 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
4942 int32_t skiprows=c.skipanimy;
4943
4944 TileHelper::OverTileCloaked(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
4945 }
4946
4947
4948 167483 void bmp_do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4949 {
4950 /* layer, x, y, tile, color opacity */
4951 //sdci[17] Bitmap Pointer
4952
4953 167483 int32_t opacity = sdci[6]/10000;
4954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 167483 times.
167483 if ( sdci[17] <= 0 )
4955 {
4956 Z_scripterrlog("bitmap->FastTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4957 return;
4958 }
4959 167483 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4960
1/2
✓ Branch 0 taken 167483 times.
✗ Branch 1 not taken.
167483 if ( refbmp == NULL ) return;
4961
4962
2/4
✓ Branch 0 taken 167483 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 167483 times.
✗ Branch 3 not taken.
167483 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4963
4964
2/2
✓ Branch 0 taken 11131 times.
✓ Branch 1 taken 156352 times.
167483 if(opacity < 128)
4965 11131 overtiletranslucent16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
4966 else
4967 156352 overtile16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
4968 167483 }
4969
4970 19821648 void do_bmpwritetile(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4971 {
4972 /* layer, x, y, tile, is8bit, mask */
4973 //sdci[17] Bitmap Pointer
4974
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19821648 times.
19821648 if ( sdci[17] <= 0 )
4975 {
4976 Z_scripterrlog("bitmap->WriteTile() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4977 return;
4978 }
4979 19821648 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
4980
1/2
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
19821648 if ( refbmp == NULL ) return;
4981
4982
2/4
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19821648 times.
✗ Branch 3 not taken.
19821648 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
4983
4984 19821648 int32_t x = (sdci[2]/10000), y = (sdci[3]/10000), tl = (sdci[4]/10000);
4985 19821648 bool is8bit = sdci[5]!=0, mask = sdci[6]!=0;
4986
4987 19821648 write_tile(newtilebuf, refbmp, tl, x+xoffset, y+yoffset, is8bit, mask);
4988 19821648 }
4989
4990 void do_bmpdither(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4991 {
4992 /* layer, mask, color, ditherType, ditherArg */
4993 //sdci[2] Mask Bitmap Pointer
4994 //sdci[3] Color
4995 //sdci[17] Bitmap Pointer
4996 if ( sdci[17] <= 0 )
4997 {
4998 Z_scripterrlog("bitmap->Dither() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
4999 return;
5000 }
5001 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5002 if ( refbmp == NULL ) return;
5003 if ( sdci[2] <= 0 )
5004 {
5005 Z_scripterrlog("bitmap->Dither() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5006 return;
5007 }
5008 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5009 if ( mask == NULL ) return;
5010
5011 int32_t dType = sdci[4] / 10000L;
5012 if(dType < 0 || dType >= dithMax)
5013 {
5014 Z_scripterrlog("bitmap->Dither() used an invalid dither type: %d. Aborting.\n", dType);
5015 return;
5016 }
5017
5018 ditherblit(refbmp, mask, byte(sdci[3]/10000L), dType, sdci[5]/10000L);
5019 }
5020
5021 6363 void do_bmpreplcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5022 {
5023 /* layer, shift, startcol, endcol */
5024 //sdci[2] NewCol
5025 //sdci[3] StartCol
5026 //sdci[4] EndCol
5027 //sdci[17] Bitmap Pointer
5028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6363 times.
6363 if ( sdci[17] <= 0 )
5029 {
5030 Z_scripterrlog("bitmap->ReplaceColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5031 return;
5032 }
5033 6363 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6363 times.
6363 if ( refbmp == NULL ) return;
5035 6363 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, false);
5036 6363 }
5037
5038 void do_bmpshiftcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5039 {
5040 /* layer, shift, startcol, endcol */
5041 //sdci[2] ShiftAmount
5042 //sdci[3] StartCol
5043 //sdci[4] EndCol
5044 //sdci[17] Bitmap Pointer
5045 if ( sdci[17] <= 0 )
5046 {
5047 Z_scripterrlog("bitmap->ShiftColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5048 return;
5049 }
5050 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5051 if ( refbmp == NULL ) return;
5052 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, true);
5053 }
5054
5055 906 void do_bmpmaskdraw(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5056 {
5057 /* layer, mask, color */
5058 //sdci[2] Mask Bitmap Pointer
5059 //sdci[3] Color
5060 //sdci[4] start mask color
5061 //sdci[5] end mask color
5062 //sdci[17] Bitmap Pointer
5063 906 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5064
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( refbmp == NULL )
5065 {
5066 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5067 return;
5068 }
5069 906 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5070
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( mask == NULL )
5071 {
5072 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5073 return;
5074 }
5075 906 auto fillcol = sdci[3]/10000L;
5076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(unsigned(fillcol) > 0xFF) return; //invalid color, nothing to draw
5077 906 auto startcol = vbound(sdci[4]/10000L,0x00,0xFF);
5078 906 auto endcol = vbound(sdci[5]/10000L,0x00,0xFF);
5079 906 mask_colorfill(refbmp, mask, fillcol, startcol, endcol);
5080 906 }
5081
5082 void do_bmpmaskblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5083 {
5084 /* layer, mask, color */
5085 //sdci[2] Mask Bitmap Pointer
5086 //sdci[3] Pattern Bitmap
5087 //sdci[4] bool 'pattern repeats'
5088 //sdci[5] start mask color
5089 //sdci[6] end mask color
5090 //sdci[17] Bitmap Pointer
5091 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5092 if ( refbmp == NULL )
5093 {
5094 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5095 return;
5096 }
5097 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5098 if ( mask == NULL )
5099 {
5100 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (mask) id: %d. Aborting.\n", sdci[2]);
5101 return;
5102 }
5103 BITMAP *pattern = FFCore.GetScriptBitmap(sdci[3]);
5104 if ( pattern == NULL )
5105 {
5106 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (pattern) id: %d. Aborting.\n", sdci[3]);
5107 return;
5108 }
5109 bool repeats = sdci[4]!=0;
5110 auto startcol = vbound(sdci[5]/10000L,0x00,0xFF);
5111 auto endcol = vbound(sdci[6]/10000L,0x00,0xFF);
5112 mask_blit(refbmp, mask, pattern, repeats, startcol, endcol);
5113 }
5114
5115 32636464 void bmp_do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5116 {
5117 /* layer, x, y, tile, color opacity */
5118 //sdci[17] Bitmap Pointer
5119 32636464 int32_t opacity = sdci[6] / 10000;
5120 32636464 int32_t x1 = sdci[2] / 10000;
5121 32636464 int32_t y1 = sdci[3] / 10000;
5122 32636464 int32_t index = sdci[4]/10000;
5123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if ( sdci[17] <= 0 )
5124 {
5125 Z_scripterrlog("bitmap->FastCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5126 return;
5127 }
5128 32636464 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5129
1/2
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
32636464 if ( refbmp == NULL ) return;
5130 32636464 int32_t cmb = (sdci[4]/10000);
5131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if((unsigned)cmb >= MAXCOMBOS)
5132 {
5133 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
5134 return;
5135 }
5136
5137
2/4
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32636464 times.
✗ Branch 3 not taken.
32636464 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5138
5139 //if( index >= MAXCOMBOS ) return; //bleh.
5140 /*
5141 const newcombo & c = combobuf[index];
5142
5143 if(opacity < 128)
5144 overtiletranslucent16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip, opacity);
5145 else
5146 overtile16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip);
5147 */
5148
5149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if(opacity < 128)
5150 {
5151 //void overcomboblocktranslucent(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h, int32_t opacity)
5152 overcomboblocktranslucent(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
5153
5154 }
5155 else
5156 {
5157 //overcomboblock(BITMAP *dest, int32_t x, int32_t y, int32_t cmbdat, int32_t cset, int32_t w, int32_t h)
5158 32636464 overcomboblock(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
5159 }
5160 32636464 }
5161
5162
5163
5164 void bmp_do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5165 {
5166 //sdci[17] Bitmap Pointer
5167 if ( sdci[17] <= 0 )
5168 {
5169 Z_scripterrlog("bitmap->DrawCharacter() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5170 return;
5171 }
5172 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5173 if ( refbmp == NULL ) return;
5174
5175 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5176
5177 //broken 2.50.2 and earlier drawcharacter()
5178 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5179 {
5180 //sdci[1]=layer
5181 //sdci[2]=x
5182 //sdci[3]=y
5183 //sdci[4]=font
5184 //sdci[5]=color
5185 //sdci[6]=bg color
5186 //sdci[7]=strech x (width)
5187 //sdci[8]=stretch y (height)
5188 //sdci[9]=char
5189 //sdci[10]=opacity
5190 //sdci[17] Bitmap Pointer
5191
5192 int32_t x=sdci[2]/10000;
5193 int32_t y=sdci[3]/10000;
5194 int32_t font_index=sdci[4]/10000;
5195 int32_t color=sdci[5]/10000;
5196 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5197 int32_t w=sdci[7]/10000;
5198 int32_t h=sdci[8]/10000;
5199 char glyph=char(sdci[9]/10000);
5200 int32_t opacity=sdci[10]/10000;
5201
5202 //safe check
5203 if(bg_color < -1) bg_color = -1;
5204
5205 if(w>512) w=512; //w=vbound(w,0,512);
5206
5207 if(h>512) h=512; //h=vbound(h,0,512);
5208
5209 //undone
5210 if(w>0&&h>0)//stretch the character
5211 {
5212 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5213
5214 if(opacity < 128)
5215 {
5216 if(w>128||h>128)
5217 {
5218 clear_bitmap(prim_bmp);
5219
5220 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5221 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5222 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5223 }
5224 else //this is faster
5225 {
5226 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5227
5228 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5229 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5230 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5231
5232 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5233 }
5234 }
5235 else // no opacity
5236 {
5237 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5238 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5239 }
5240
5241 }
5242 else //no stretch
5243 {
5244 if(opacity < 128)
5245 {
5246 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5247 clear_bitmap(pbmp);
5248
5249 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5250 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5251
5252 destroy_bitmap(pbmp);
5253 }
5254 else // no opacity
5255 {
5256 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5257 }
5258 }
5259 }
5260
5261 else //2.53.0 fixed version and later.
5262 {
5263
5264 //sdci[1]=layer
5265 //sdci[2]=x
5266 //sdci[3]=y
5267 //sdci[4]=font
5268 //sdci[5]=color
5269 //sdci[6]=bg color
5270 //sdci[7]=strech x (width)
5271 //sdci[8]=stretch y (height)
5272 //sdci[9]=char
5273 //sdci[10]=opacity
5274
5275 int32_t x=sdci[2]/10000;
5276 int32_t y=sdci[3]/10000;
5277 int32_t font_index=sdci[4]/10000;
5278 int32_t color=sdci[5]/10000;
5279 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5280 int32_t w=sdci[7]/10000;
5281 int32_t h=sdci[8]/10000;
5282 char glyph=char(sdci[9]/10000);
5283 int32_t opacity=sdci[10]/10000;
5284
5285 //safe check
5286 if(bg_color < -1) bg_color = -1;
5287
5288 if(w>512) w=512; //w=vbound(w,0,512);
5289
5290 if(h>512) h=512; //h=vbound(h,0,512);
5291
5292 //undone
5293 if(w>0&&h>0)//stretch the character
5294 {
5295 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5296
5297 if(opacity < 128)
5298 {
5299 if(w>128||h>128)
5300 {
5301 clear_bitmap(prim_bmp);
5302
5303 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5304 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5305 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5306 }
5307 else //this is faster
5308 {
5309 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5310
5311 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5312 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5313 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5314
5315 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5316 }
5317 }
5318 else // no opacity
5319 {
5320 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5321 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5322 }
5323
5324 }
5325 else //no stretch
5326 {
5327 if(opacity < 128)
5328 {
5329 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5330 clear_bitmap(pbmp);
5331
5332 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5333 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5334
5335 destroy_bitmap(pbmp);
5336 }
5337 else // no opacity
5338 {
5339 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5340 }
5341 }
5342
5343 }
5344
5345 }
5346
5347
5348 void bmp_do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5349 {
5350 if ( sdci[17] <= 0 )
5351 {
5352 Z_scripterrlog("bitmap->DrawInteger() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5353 return;
5354 }
5355 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5356 if ( refbmp == NULL ) return;
5357
5358 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5359
5360 //broken 2.50.2 and earlier drawinteger()
5361 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5362 {
5363 //sdci[1]=layer
5364 //sdci[2]=x
5365 //sdci[3]=y
5366 //sdci[4]=font
5367 //sdci[5]=color
5368 //sdci[6]=bg color
5369 //sdci[7]=strech x (width)
5370 //sdci[8]=stretch y (height)
5371 //sdci[9]=integer
5372 //sdci[10]=num decimal places
5373 //sdci[11]=opacity
5374 //sdci[17] Bitmap Pointer
5375
5376 int32_t x=sdci[2]/10000;
5377 int32_t y=sdci[3]/10000;
5378 int32_t font_index=sdci[4]/10000;
5379 int32_t color=sdci[5]/10000;
5380 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5381 int32_t w=sdci[7]/10000;
5382 int32_t h=sdci[8]/10000;
5383 //float number=static_cast<float>(sdci[9])/10000.0f;
5384 int32_t decplace=sdci[10]/10000;
5385 int32_t opacity=sdci[11]/10000;
5386
5387 //safe check
5388 if(bg_color < -1) bg_color = -1;
5389
5390 if(w>512) w=512; //w=vbound(w,0,512);
5391
5392 if(h>512) h=512; //h=vbound(h,0,512);
5393
5394 char numbuf[15];
5395
5396 switch(decplace)
5397 {
5398 default:
5399 case 0:
5400 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5401 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5402
5403 case 1:
5404 //sprintf(numbuf,"%.01f",number);
5405 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5406 break;
5407
5408 case 2:
5409 //sprintf(numbuf,"%.02f",number);
5410 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5411 break;
5412
5413 case 3:
5414 //sprintf(numbuf,"%.03f",number);
5415 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5416 break;
5417
5418 case 4:
5419 //sprintf(numbuf,"%.04f",number);
5420 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5421 break;
5422 }
5423
5424 if(w>0&&h>0)//stretch
5425 {
5426 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5427
5428 if(opacity < 128)
5429 {
5430 if(w>128||h>128)
5431 {
5432 clear_bitmap(prim_bmp);
5433
5434 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5435 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5436 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5437 }
5438 else
5439 {
5440 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5441 clear_bitmap(pbmp2);
5442
5443 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5444 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5445 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5446
5447 destroy_bitmap(pbmp2);
5448 }
5449 }
5450 else // no opacity
5451 {
5452 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5453 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5454 }
5455
5456 }
5457 else //no stretch
5458 {
5459 if(opacity < 128)
5460 {
5461 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5462 clear_bitmap(pbmp);
5463
5464 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5465 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5466
5467 destroy_bitmap(pbmp);
5468 }
5469 else // no opacity
5470 {
5471 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5472 }
5473 }
5474
5475 }
5476
5477 else //2.53.0 fixed version and later.
5478 {
5479 //sdci[1]=layer
5480 //sdci[2]=x
5481 //sdci[3]=y
5482 //sdci[4]=font
5483 //sdci[5]=color
5484 //sdci[6]=bg color
5485 //sdci[7]=strech x (width)
5486 //sdci[8]=stretch y (height)
5487 //sdci[9]=integer
5488 //sdci[10]=num decimal places
5489 //sdci[11]=opacity
5490
5491 int32_t x=sdci[2]/10000;
5492 int32_t y=sdci[3]/10000;
5493 int32_t font_index=sdci[4]/10000;
5494 int32_t color=sdci[5]/10000;
5495 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5496 int32_t w=sdci[7]/10000;
5497 int32_t h=sdci[8]/10000;
5498 //float number=static_cast<float>(sdci[9])/10000.0f;
5499 //int32_t numberint = sdci[9]/10000;
5500 int32_t decplace=sdci[10]/10000;
5501 int32_t opacity=sdci[11]/10000;
5502
5503 //safe check
5504 if(bg_color < -1) bg_color = -1;
5505
5506 if(w>512) w=512; //w=vbound(w,0,512);
5507
5508 if(h>512) h=512; //h=vbound(h,0,512);
5509
5510 char numbuf[15];
5511
5512 switch(decplace)
5513 {
5514 default:
5515 case 0:
5516 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5517 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5518
5519 case 1:
5520 //sprintf(numbuf,"%.01f",number);
5521 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5522 break;
5523
5524 case 2:
5525 //sprintf(numbuf,"%.02f",number);
5526 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5527 break;
5528
5529 case 3:
5530 //sprintf(numbuf,"%.03f",number);
5531 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5532 break;
5533
5534 case 4:
5535 //sprintf(numbuf,"%.04f",number);
5536 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5537 break;
5538 }
5539
5540 //FONT* font=get_zc_font(sdci[4]/10000);
5541
5542 if(w>0&&h>0)//stretch
5543 {
5544 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
5545 clear_bitmap(pbmp);
5546 //script_drawing_commands.GetSmallTextureBitmap(1,1);
5547
5548 if(opacity < 128)
5549 {
5550 if(w>128||h>128)
5551 {
5552 clear_bitmap(prim_bmp);
5553
5554 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5555 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5556 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5557 }
5558 else
5559 {
5560 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5561 clear_bitmap(pbmp2);
5562
5563 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5564 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5565 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5566
5567 destroy_bitmap(pbmp2);
5568 }
5569 }
5570 else // no opacity
5571 {
5572 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5573 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5574 }
5575
5576 }
5577 else //no stretch
5578 {
5579 if(opacity < 128)
5580 {
5581 FONT* font = get_zc_font(font_index);
5582 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
5583 clear_bitmap(pbmp);
5584
5585 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
5586 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5587
5588 destroy_bitmap(pbmp);
5589 }
5590 else // no opacity
5591 {
5592 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5593 }
5594 }
5595 }
5596 }
5597
5598
5599 873 void bmp_do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5600 {
5601 //sdci[1]=layer
5602 //sdci[2]=x
5603 //sdci[3]=y
5604 //sdci[4]=font
5605 //sdci[5]=color
5606 //sdci[6]=bg color
5607 //sdci[7]=format_option
5608 //sdci[8]=string
5609 //sdci[9]=opacity
5610 //sdci[17] Bitmap Pointer
5611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 873 times.
873 if ( sdci[17] <= 0 )
5612 {
5613 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5614 return;
5615 }
5616
5617 873 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5618
1/2
✓ Branch 0 taken 873 times.
✗ Branch 1 not taken.
873 if ( refbmp == NULL ) return;
5619
5620
2/4
✓ Branch 0 taken 873 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 873 times.
873 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5621
5622 873 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5623
5624
1/2
✓ Branch 0 taken 873 times.
✗ Branch 1 not taken.
873 if(!str)
5625 {
5626 al_trace("String pointer is null! Internal error. \n");
5627 return;
5628 }
5629
5630 873 int32_t x=sdci[2]/10000;
5631 873 int32_t y=sdci[3]/10000;
5632 873 FONT* font=get_zc_font(sdci[4]/10000);
5633 873 int32_t color=sdci[5]/10000;
5634 873 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5635 873 int32_t format_type=sdci[7]/10000;
5636 873 int32_t opacity=sdci[9]/10000;
5637 //sdci[8] not needed :)
5638
5639 //safe check
5640
1/2
✓ Branch 0 taken 873 times.
✗ Branch 1 not taken.
873 if(bg_color < -1) bg_color = -1;
5641
5642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 873 times.
873 if(opacity < 128)
5643 {
5644 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5645 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5646 clear_bitmap(pbmp);
5647 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
5648 if(format_type == 2) // right-sided text
5649 x-=width;
5650 else if(format_type == 1) // centered text
5651 x-=width/2;
5652 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5653 destroy_bitmap(pbmp);
5654 }
5655 else // no opacity
5656 {
5657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 873 times.
873 if(format_type == 2) // right-sided text
5658 {
5659 textout_right_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5660 }
5661
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 855 times.
873 else if(format_type == 1) // centered text
5662 {
5663 18 textout_centre_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5664 18 }
5665 else // standard left-sided text
5666 {
5667 855 textout_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5668 }
5669 }
5670 873 }
5671
5672 45504 void bmp_do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5673 {
5674 //sdci[1]=layer
5675 //sdci[2]=x
5676 //sdci[3]=y
5677 //sdci[4]=font
5678 //sdci[5]=color
5679 //sdci[6]=bg color
5680 //sdci[7]=format_option
5681 //sdci[8]=string
5682 //sdci[9]=opacity
5683 //sdci[10]=shadowtype
5684 //sdci[11]=shadow_color
5685 //sdci[17] Bitmap Pointer
5686
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if ( sdci[17] <= 0 )
5687 {
5688 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5689 return;
5690 }
5691
5692 45504 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5693
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if ( refbmp == NULL ) return;
5694
5695
2/4
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45504 times.
45504 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5696
5697 45504 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5698
5699
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(!str)
5700 {
5701 al_trace("String pointer is null! Internal error. \n");
5702 return;
5703 }
5704
5705 45504 int32_t x=sdci[2]/10000;
5706 45504 int32_t y=sdci[3]/10000;
5707 45504 FONT* font=get_zc_font(sdci[4]/10000);
5708 45504 int32_t color=sdci[5]/10000;
5709 45504 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5710 45504 int32_t format_type=sdci[7]/10000;
5711 45504 int32_t opacity=sdci[9]/10000;
5712 45504 int32_t textstyle = sdci[10]/10000;
5713 45504 int32_t shadow_color = sdci[11]/10000;
5714 //sdci[8] not needed :)
5715
5716 //safe check
5717
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(bg_color < -1) bg_color = -1;
5718
5719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if(opacity < 128)
5720 {
5721 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5722 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5723 clear_bitmap(pbmp);
5724 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
5725 if(format_type == 2) // right-sided text
5726 x-=width;
5727 else if(format_type == 1) // centered text
5728 x-=width/2;
5729 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5730 destroy_bitmap(pbmp);
5731 }
5732 else // no opacity
5733 {
5734 45504 textout_styled_aligned_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
5735 }
5736 45504 }
5737
5738 324166 void bmp_do_clearr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5739 {
5740
1/2
✓ Branch 0 taken 324166 times.
✗ Branch 1 not taken.
324166 if ( sdci[17] <= 0 )
5741 {
5742 Z_scripterrlog("bitmap->Clear() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5743 return;
5744 }
5745 324166 int32_t bitid = sdci[17];
5746 324166 auto& usr_bitmap = scb.get(bitid);
5747
1/2
✓ Branch 0 taken 324166 times.
✗ Branch 1 not taken.
324166 if (usr_bitmap.u_bmp)
5748 324166 clear_bitmap(usr_bitmap.u_bmp);
5749 324166 }
5750
5751 2790 void bmp_do_clearcolorr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5752 {
5753 //sdci[1]=layer
5754 //sdci[2]=color
5755 //sdci[17] Bitmap Pointer
5756 2790 int32_t pal_color = sdci[2]/10000;
5757
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if ( sdci[17] <= 0 )
5758 {
5759 Z_scripterrlog("bitmap->ClearToColor() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5760 return;
5761 }
5762 2790 int32_t bitid = sdci[17];
5763 2790 auto& usr_bitmap = scb.get(bitid);
5764
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if (usr_bitmap.u_bmp)
5765 2790 clear_to_color(usr_bitmap.u_bmp, pal_color);
5766 2790 }
5767
5768
5769 34653 void bmp_do_regenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5770 {
5771 //sdci[1]=layer
5772 34653 int32_t h = sdci[3]/10000;
5773 34653 int32_t w = sdci[2]/10000;
5774
1/2
✓ Branch 0 taken 34653 times.
✗ Branch 1 not taken.
34653 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
5775 {
5776 //flip height and width
5777 h = h ^ w;
5778 w = h ^ w;
5779 h = h ^ w;
5780 }
5781 //sdci[17] Bitmap Pointer
5782 //Z_scripterrlog("bitmap->Create() pointer is: %d\n", sdci[17]);
5783
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34653 times.
34653 if ( sdci[17] <= 0 )
5784 {
5785 Z_scripterrlog("bitmap->Create() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5786 return;
5787 }
5788 34653 int32_t bitid = sdci[17];
5789 34653 auto& usr_bmp = scb.get(bitid);
5790
2/2
✓ Branch 0 taken 34528 times.
✓ Branch 1 taken 125 times.
34653 if ( usr_bmp.u_bmp )
5791 34528 destroy_bitmap(usr_bmp.u_bmp);
5792 34653 usr_bmp.u_bmp = create_bitmap_ex(8,w,h);
5793
5794 34653 usr_bmp.width = w;
5795 34653 usr_bmp.height = h;
5796 34653 }
5797
5798 void bmp_do_readr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5799 {
5800 //sdci[1]=layer
5801 //sdci[2]=filename
5802 //sdci[3]=y
5803 //sdci[4]=font
5804 //sdci[5]=color
5805 //sdci[6]=bg color
5806 //sdci[7]=format_option
5807 //sdci[8]=string
5808 //sdci[9]=opacity
5809 //sdci[17] Bitmap Pointer
5810 //Z_scripterrlog("bitmap->Read() pointer is: %d\n", sdci[17]);
5811 if ( sdci[17] <= 0 )
5812 {
5813 Z_scripterrlog("bitmap->Read() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5814 return;
5815 }
5816 int32_t bitid = sdci[17];
5817 auto& usr_bitmap = scb.get(bitid);
5818 usr_bitmap.destroy();
5819
5820 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5821
5822 if(!str)
5823 {
5824 al_trace("String pointer is null! Internal error. \n");
5825 return;
5826 }
5827
5828 PALETTE tempPal;
5829 get_palette(tempPal);
5830 if ( checkPath(str->c_str(), false) )
5831 {
5832 usr_bitmap.u_bmp = load_bitmap(str->c_str(), tempPal);
5833 usr_bitmap.width = usr_bitmap.u_bmp->w;
5834 usr_bitmap.height = usr_bitmap.u_bmp->h;
5835 if ( !usr_bitmap.u_bmp )
5836 {
5837 Z_scripterrlog("Failed to load image file %s.\nMaking a blank bitmap on the pointer.\n", str->c_str());
5838 }
5839 else
5840 {
5841 zprint("Read image file %s\n",str->c_str());
5842 }
5843 }
5844 else
5845 {
5846 Z_scripterrlog("Failed to load image file: %s. File not found. Creating a blank bitmap on the pointer.\n", str->c_str());
5847 usr_bitmap.u_bmp = create_bitmap_ex(8,256,176);
5848 clear_bitmap(usr_bitmap.u_bmp);
5849 }
5850 }
5851
5852
5853
5854 3 void bmp_do_writer(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5855 {
5856 //sdci[1]=layer
5857 //sdci[2]=filename
5858 //sdci[3]=y
5859 //sdci[4]=font
5860 //sdci[5]=color
5861 //sdci[6]=bg color
5862 //sdci[7]=format_option
5863 //sdci[8]=string
5864 //sdci[9]=opacity
5865 //sdci[17] Bitmap Pointer
5866 //Z_scripterrlog("bitmap->Write() pointer is: %d\n", sdci[17]);
5867
5868
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( sdci[17] <= 0 )
5869 {
5870 Z_scripterrlog("bitmap->Write() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5871 return;
5872 }
5873 3 int32_t bitid = sdci[17];
5874 3 auto& usr_bitmap = scb.get(bitid);
5875
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (!usr_bitmap.u_bmp)
5876 {
5877 Z_scripterrlog("Tried to write from an invalid bitmap pointer %d. Aborting. \n", sdci[17]);
5878 return;
5879 }
5880
5881 3 bool overwrite = (sdci[3] != 0);
5882 3 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5883
5884
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!str)
5885 {
5886 al_trace("String pointer is null! Internal error. \n");
5887 return;
5888 }
5889
5890 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
5891 //std::strncpy(cptr, str->c_str(), str->size());
5892 //Z_scripterrlog("bitmap->Write extension matches ? : %s\n!", (FFCore.checkExtension(str->c_str(), ".png")) ? "true" : "false");
5893 //Z_scripterrlog("Trying to write filename %s\n", cptr);
5894 if
5895 (
5896
14/48
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 3 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 3 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 3 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 3 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 3 times.
✗ Branch 26 not taken.
✓ Branch 27 taken 3 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
6 ( (FFCore.checkExtension(*str, "")) ) ||
5897
3/16
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
3 ( !(FFCore.checkExtension(*str, ".png")) && !(FFCore.checkExtension(*str, ".gif")) && !(FFCore.checkExtension(*str, ".bmp"))
5898 && !(FFCore.checkExtension(*str, ".pcx")) && !(FFCore.checkExtension(*str, ".tga")) )
5899 )
5900 {
5901 Z_scripterrlog("No extension, or invalid extension provided for writing bitmap file %s. Could not write the file.\nValid types are .png, .gif, .pcx, .tgx, and .bmp. Aborting.\n",str->c_str());
5902 }
5903
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 else if ( overwrite || (!checkPath(str->c_str(), false)) )
5904 {
5905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if(create_path(str->c_str()))
5906 {
5907 save_bitmap(str->c_str(), usr_bitmap.u_bmp, RAMpal);
5908 if(checkPath(str->c_str(), false))
5909 {
5910 zprint("Wrote image file %s\n",str->c_str());
5911 }
5912 else
5913 {
5914 Z_scripterrlog("Failed to create file '%s'\n",str->c_str());
5915 }
5916 }
5917 else
5918 {
5919 3 Z_scripterrlog("Cannot write file '%s' because the directory does not exist, and could not be created.\n", str->c_str());
5920 }
5921 3 }
5922 else Z_scripterrlog("Cannot write file '%s' because the file already exists in the specified path.\n", str->c_str());
5923 3 }
5924
5925
5926 void bmp_do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5927 {
5928 //sdci[1]=layer
5929 //sdci[2]=x1
5930 //sdci[3]=y1
5931 //sdci[4]=x2
5932 //sdci[5]=y2
5933 //sdci[6]=x3
5934 //sdci[7]=y3
5935 //sdci[8]=x4
5936 //sdci[9]=y4
5937 //sdci[10]=width
5938 //sdci[11]=height
5939 //sdci[12]=cset
5940 //sdci[13]=flip
5941 //sdci[14]=tile/combo
5942 //sdci[15]=polytype
5943 //sdci[16] = other bitmap as texture
5944 //sdci[17] Bitmap Pointer
5945 Z_scripterrlog("bitmap quad pointer: %d\n", sdci[17]);
5946 if ( sdci[17] <= 0 )
5947 {
5948 Z_scripterrlog("bitmap->Quad() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
5949 return;
5950 }
5951 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
5952
5953 if ( !refbmp ) return;
5954
5955 int32_t x1 = sdci[2]/10000;
5956 int32_t y1 = sdci[3]/10000;
5957 int32_t x2 = sdci[4]/10000;
5958 int32_t y2 = sdci[5]/10000;
5959 int32_t x3 = sdci[6]/10000;
5960 int32_t y3 = sdci[7]/10000;
5961 int32_t x4 = sdci[8]/10000;
5962 int32_t y4 = sdci[9]/10000;
5963 int32_t w = sdci[10]/10000;
5964 int32_t h = sdci[11]/10000;
5965 int32_t color = sdci[12]/10000;
5966 int32_t flip=(sdci[13]/10000)&3;
5967 int32_t tile = sdci[14]/10000;
5968 int32_t polytype = sdci[15]/10000;
5969 int32_t quad_render_source = sdci[16];
5970 //Z_scripterrlog("bitmap->Quad() render source is: %d\n", quad_render_source);
5971
5972 bool tex_is_bitmap = ( sdci[16] != 0 );
5973
5974 BITMAP *bmptexture=NULL;
5975 BITMAP *tex=NULL;
5976 polytype = vbound(polytype, 0, 14);
5977
5978 int32_t col[4];
5979 col[0]=col[1]=col[2]=col[3]=color;
5980 bool mustDestroyBmp = false;
5981
5982 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
5983
5984 if ( tex_is_bitmap )
5985 {
5986 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
5987 if ( !bmptexture )
5988 {
5989 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
5990 tex_is_bitmap = 0;
5991 }
5992 }
5993
5994 if ( tex_is_bitmap )
5995 {
5996
5997 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
5998 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
5999 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", w);
6000 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", h);
6001
6002 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6003 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6004 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6005 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6006
6007 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
6008 }
6009 else
6010 {
6011 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6012 if(!tex)
6013 {
6014 //Z_scripterrlog("Bitmap->Quad() found an invalid texture bitmap.\n");
6015 mustDestroyBmp = true;
6016 tex = create_bitmap_ex(8, w*16, h*16);
6017 clear_bitmap(tex);
6018 }
6019
6020 if(tile > 0) // TILE
6021 {
6022 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6023 }
6024
6025 if ( tile < 0 ) // COMBO
6026 {
6027 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
6028 const int32_t tiletodraw = combo_tile(c, x1, y1);
6029 flip = flip ^ c.flip;
6030
6031 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6032 }
6033 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6034 {
6035 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6036 return; //non power of two error
6037 }
6038 //Z_scripterrlog("bitmap->Quad() is trying to blit from a bitmap texture.\n");
6039 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6040 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6041 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6042 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6043
6044 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
6045
6046 }
6047
6048
6049
6050
6051 //todo: finish palette shading
6052 /*
6053 POLYTYPE_FLAT
6054 POLYTYPE_GCOL
6055 POLYTYPE_GRGB
6056 POLYTYPE_ATEX
6057 POLYTYPE_PTEX
6058 POLYTYPE_ATEX_MASK
6059 POLYTYPE_PTEX_MASK
6060 POLYTYPE_ATEX_LIT
6061 POLYTYPE_PTEX_LIT
6062 POLYTYPE_ATEX_MASK_LIT
6063 POLYTYPE_PTEX_MASK_LIT
6064 POLYTYPE_ATEX_TRANS
6065 POLYTYPE_PTEX_TRANS
6066 POLYTYPE_ATEX_MASK_TRANS
6067 POLYTYPE_PTEX_MASK_TRANS
6068 */
6069
6070 if(mustDestroyBmp)
6071 destroy_bitmap(tex);
6072
6073 }
6074
6075
6076 void bmp_do_getpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6077 {
6078 //sdci[1]=layer
6079 //sdci[2]=x1
6080 //sdci[3]=y1
6081
6082 //sdci[17] Bitmap Pointer
6083 if ( sdci[17] <= 0 )
6084 {
6085 Z_scripterrlog("bitmap->GetPixel() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[17]);
6086 return;
6087 }
6088 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
6089 if ( refbmp == NULL ) return;
6090
6091
6092 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6093
6094 int32_t x1 = sdci[2]/10000;
6095 int32_t y1 = (sdci[3]/10000)+yoffset;
6096 int32_t col = getpixel(scb.get(sdci[17]).u_bmp, x1, y1);
6097 Z_scripterrlog("bitmap->GetPixel col is %d\n",col);
6098 Z_scripterrlog("bitmap->GetPixel bitmap ptr is is %d\n",(sdci[17]));
6099 FFCore.set_sarg1(col);
6100 }
6101
6102
6103
6104
6105 void bmp_do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6106 {
6107 //sdci[1]=layer
6108 //sdci[2]=x1
6109 //sdci[3]=y1
6110 //sdci[4]=x2
6111 //sdci[5]=y2
6112 //sdci[6]=x3
6113 //sdci[7]=y3
6114 //sdci[8]=width
6115 //sdci[9]=height
6116 //sdci[10]=cset
6117 //sdci[11]=flip
6118 //sdci[12]=tile/combo
6119 //sdci[13]=polytype
6120 //sdci[17] Bitmap Pointer
6121 if ( sdci[17] <= 0 )
6122 {
6123 Z_scripterrlog("bitmap->Triangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
6124 return;
6125 }
6126 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
6127 if ( refbmp == NULL ) return;
6128
6129
6130 int32_t render_source = sdci[14];
6131 //Z_scripterrlog("bitmap->Triangle() render source is: %d\n", render_source);
6132
6133 bool tex_is_bitmap = ( sdci[14] != 0 );
6134
6135 BITMAP *bmptexture=NULL;
6136 if ( tex_is_bitmap )
6137 {
6138 bmptexture = FFCore.GetScriptBitmap(render_source);
6139 if ( !bmptexture )
6140 {
6141 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6142 tex_is_bitmap = 0;
6143 }
6144 }
6145
6146 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6147
6148 int32_t x1 = sdci[2]/10000;
6149 int32_t y1 = sdci[3]/10000;
6150 int32_t x2 = sdci[4]/10000;
6151 int32_t y2 = sdci[5]/10000;
6152 int32_t x3 = sdci[6]/10000;
6153 int32_t y3 = sdci[7]/10000;
6154 int32_t w = sdci[8]/10000;
6155 int32_t h = sdci[9]/10000;
6156 int32_t color = sdci[10]/10000;
6157 int32_t flip=(sdci[11]/10000)&3;
6158 int32_t tile = sdci[12]/10000;
6159 int32_t polytype = sdci[13]/10000;
6160
6161 polytype = vbound(polytype, 0, 14);
6162 int32_t utex_w = w;
6163 int32_t utex_h = h;
6164
6165
6166 int32_t tex_width = w*16;
6167 int32_t tex_height = h*16;
6168
6169 bool mustDestroyBmp = false;
6170 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6171
6172 if(!tex)
6173 {
6174 mustDestroyBmp = true;
6175 tex = create_bitmap_ex(8, tex_width, tex_height);
6176 clear_bitmap(tex);
6177 }
6178
6179 int32_t col[3];
6180 /*
6181 if( color < 0 )
6182 {
6183 col[0]=draw_container.color_buffer[0];
6184 col[1]=draw_container.color_buffer[1];
6185 col[2]=draw_container.color_buffer[2];
6186 }
6187 else */
6188 {
6189 col[0]=col[1]=col[2]=color;
6190 }
6191
6192 if(tile > 0) // TILE
6193 {
6194 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6195 }
6196 else // COMBO
6197 {
6198 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
6199 const int32_t tiletodraw = combo_tile(c, x1, y1);
6200 flip = flip ^ c.flip;
6201
6202 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6203 }
6204 if ( !tex_is_bitmap )
6205 {
6206 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6207 {
6208 Z_message("bitmap->Triangle() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6209 return; //non power of two error
6210 }
6211 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6212 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
6213 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
6214
6215
6216 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
6217
6218 }
6219
6220 else
6221 {
6222 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6223 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6224 if ( !isPowerOfTwo(utex_h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_w);
6225 if ( !isPowerOfTwo(utex_w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_h);
6226
6227 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6228 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(utex_h), col[1] };
6229 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(utex_w), static_cast<float>(utex_h), col[2] };
6230
6231
6232 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
6233
6234 }
6235
6236 if(mustDestroyBmp)
6237 destroy_bitmap(tex);
6238 }
6239
6240
6241 void bmp_do_mode7r(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6242 {
6243 /*
6244 int32_t layer, int32_t rt, int32_t srcX, int32_t srcY, int32_t srcW, int32_t srcH, int32_t destW, int32_t destH, int32_t angle, int32_t cx, int32_t cy, int32_t space_z, int32_t horizon,
6245 int32_t scale_x, int32_t scale_y){
6246
6247 //sdci[1]=layer
6248 //sdci[2]=bitmap target
6249 //
6250 // -2 is the current Render Target
6251 // -1, this is the screen (framebuf).
6252 // 0: Render target 0
6253 // 1: Render target 1
6254 // 2: Render target 2
6255 // 3: Render target 3
6256 // 4: Render target 4
6257 // 5: Render target 5
6258 // 6: Render target 6
6259 // Otherwise: The pointer to a bitmap.
6260
6261 //sdci[3]=sourcex
6262 //sdci[4]=sourcey
6263 //sdci[5]=sourcew
6264 //sdci[6]=sourceh
6265
6266 //sdci[7]=destw
6267 //sdci[8]=desth
6268 //sdci[9]=angle
6269 //scdi[10] = pivot cx
6270 //sdci[11] = pivot cy
6271 //sdci[12] = space Z
6272 //sdci[13] = horizon
6273 //scdi[14] = scale X
6274 //scdi[15] = scale Y
6275 //sdci[16] = masked?
6276 //sdci[17] Bitmap Pointer
6277
6278
6279
6280 // ZScript-side constant values:
6281 const int32_t BITDX_NORMAL = 0;
6282 const int32_t BITDX_TRANS = 1; //Translucent
6283 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6284 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6285 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6286 //Note: Some modes cannot be combined. if a combination is not supported, an error
6287 // detailing this will be shown in allegro.log.
6288
6289 //scdi[15] = litcolour
6290 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6291 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6292
6293 //sdci[16]=mask
6294
6295 */
6296
6297
6298 int32_t bitmapIndex = sdci[2];
6299 int32_t usr_bitmap_index = sdci[2];
6300 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6301 //Z_scripterrlog("DrawPlane() bitmapIndex is: %d\n", bitmapIndex);
6302
6303 if ( bitmapIndex >= 10000 )
6304 {
6305 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6306 }
6307 else if ( usr_bitmap_index > 0 )
6308 {
6309 bitmapIndex = usr_bitmap_index;
6310 // Z_scripterrlog("Mode7 is using a user bitmap target, pointer: %d\n", usr_bitmap_index);
6311 yoffset = 0;
6312 }
6313
6314 //int32_t sx = sdci[3]/10000;
6315 //int32_t sy = sdci[4]/10000;
6316 //int32_t sw = sdci[5]/10000;
6317 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
6318 //int32_t sh = sdci[6]/10000;
6319 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
6320 //int32_t dx = sdci[7]/10000;
6321 //int32_t dy = sdci[8]/10000;
6322 //int32_t dw = sdci[9]/10000;
6323 //int32_t dh = sdci[10]/10000;
6324 //float rot = sdci[11]/10000;
6325 //int32_t cx = sdci[12]/10000;
6326 //int32_t cy = sdci[13]/10000;
6327 //int32_t mode = sdci[14]/10000;
6328 //int32_t litcolour = sdci[15]/10000;
6329
6330 //rendering mode 7 args
6331 double srcX = sdci[3]/10000.0;
6332 double srcY = sdci[4]/10000.0;
6333 double destX = sdci[5]/10000.0;
6334 double destY = sdci[6]/10000.0;
6335
6336
6337 // int32_t srcW = sdci[5]/10000;
6338 // int32_t srcH = sdci[6]/10000;
6339 double destW = sdci[7]/10000.0;
6340 double destH = sdci[8]/10000.0;
6341 // int32_t angle = sdci[9]/10000;
6342 // int32_t cx = sdci[10]/10000;
6343 // int32_t cy = sdci[11]/10000;
6344 double space_z = sdci[9]/10000.0;
6345 double horizon = sdci[10]/10000.0;
6346 double scale_x = sdci[11]/10000.0;
6347 double scale_y = sdci[12]/10000.0;
6348 byte masked = ( sdci[13] ) ? 1 : 0;
6349
6350
6351 int32_t ref = 0;
6352
6353 //dx = 0 + xoffset;
6354 //dy = 0 + yoffset;
6355
6356 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6357 //Do we need to also check the render target and do the same thing if the
6358 //dest == -2 and the render target is not RT_SCREEN?
6359
6360 ref = sdci[17];
6361
6362
6363 if ( ref <= 0 )
6364 {
6365 Z_scripterrlog("bitmap->DrawPlane() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6366 return;
6367 }
6368 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6369
6370 if(!sourceBitmap)
6371 {
6372 Z_message("Warning: %d->DrawPlane() source bitmap contains invalid data or is not initialized.\n", ref);
6373 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6374 return;
6375 }
6376
6377 BITMAP *destBMP=NULL;
6378 //zprint2("mode 7 bitmap index is: %d\n",bitmapIndex);
6379 switch(bitmapIndex)
6380 {
6381 case -2:
6382 {
6383 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6384 //zprint2("current RT is: %d\n", curr_rt);
6385 if ( curr_rt >= 0 && curr_rt < 7 )
6386 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6387 else destBMP = bmp; //screen
6388 break;
6389 }
6390 case -1:
6391 destBMP = bmp; //this is framebuf, by default
6392 break;
6393 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6394 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6395 //destBMP = framebuf; //Drawing to the screen.
6396 //break;
6397
6398 //1 through 6 are the old system bitmaps (Render Targets)
6399 case 0:
6400 case 1:
6401 case 2:
6402 case 3:
6403 case 4:
6404 case 5:
6405 case 6:
6406 {
6407 //This gets a render target.
6408 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6409 break;
6410 }
6411 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6412 default:
6413 {
6414 auto& usr_bitmap = scb.get(usr_bitmap_index);
6415 destBMP = usr_bitmap.u_bmp;
6416 if ( !usr_bitmap.u_bmp )
6417 {
6418 Z_scripterrlog("Target for bitmap->DrawPlane is uninitialised. Aborting.\n");
6419 break;
6420 }
6421 }
6422 }
6423
6424 if (!destBMP)
6425 {
6426 Z_message("Warning: DrawPlane(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6427 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6428 return;
6429 }
6430
6431 //dx = dx + xoffset; //don't do this here!
6432 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6433 //All of these are a factor of 10000 as fix.
6434 int32_t screen_x = 0; int32_t screen_y = 0;
6435
6436 double distance = 0; double horizontal_scale = 0;
6437
6438 int32_t screen_y_horizon = 0;
6439
6440 double line_dx = 0; double line_dy = 0;
6441
6442 int32_t space_x = 0; int32_t space_y = 0;
6443
6444 for(screen_y = 0; screen_y < destH; screen_y++) //fix, offset by .0000
6445 {
6446 //Calculate the distance of each line from the camera point
6447 screen_y_horizon = screen_y + horizon;
6448
6449 distance = ((space_z * scale_y) / ((screen_y_horizon != 0) ? screen_y_horizon : 1));
6450
6451 //Get the scale of each line based on the distance
6452
6453 horizontal_scale = (distance / (( scale_x != 0 ) ? scale_x : 1));
6454
6455 //There was some math here before I stripped out the rotation step
6456 line_dx = horizontal_scale;
6457 line_dy = 0;
6458
6459 //space_x,space_y - where to grab each scanline from on the space bitmap
6460 space_x = srcX - destW/2.0 * line_dx;
6461 space_y = srcY - distance + destH/2.0 * line_dy;
6462
6463 //Keep blits within the bounds of both bitmaps to avoid crashes
6464 int32_t y1 = srcY+space_y;
6465 int32_t y2 = destY+screen_y;
6466 if(y1 >=0 && y1 <= (sourceBitmap->h-1) && y2 >=0 && y2 <= (destBMP->h-1) )
6467 {
6468 if ( masked ) masked_stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6469 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6470 else stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6471 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6472 }
6473 }
6474 }
6475
6476
6477 //Draw]()
6478 266215 void bmp_do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6479 {
6480 /*
6481 //sdci[1]=layer
6482 //sdci[2]=bitmap target
6483 //
6484 // -2 is the current Render Target
6485 // -1, this is the screen (framebuf).
6486 // 0: Render target 0
6487 // 1: Render target 1
6488 // 2: Render target 2
6489 // 3: Render target 3
6490 // 4: Render target 4
6491 // 5: Render target 5
6492 // 6: Render target 6
6493 // Otherwise: The pointer to a bitmap.
6494
6495 //sdci[3]=sourcex
6496 //sdci[4]=sourcey
6497 //sdci[5]=sourcew
6498 //sdci[6]=sourceh
6499 //sdci[7]=destx
6500 //sdci[8]=desty
6501 //sdci[9]=destw
6502 //sdci[10]=desth
6503 //sdci[11]=rotation/angle
6504 //scdi[12] = pivot cx
6505 //sdci[13] = pivot cy
6506 //scdi[14] = effect flags
6507 //sdci[17] Bitmap Pointer
6508
6509 // ZScript-side constant values:
6510 const int32_t BITDX_NORMAL = 0;
6511 const int32_t BITDX_TRANS = 1; //Translucent
6512 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6513 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6514 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6515 //Note: Some modes cannot be combined. if a combination is not supported, an error
6516 // detailing this will be shown in allegro.log.
6517
6518 //scdi[15] = litcolour
6519 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6520 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6521
6522 //sdci[16]=mask
6523
6524 */
6525
6526 266215 int32_t bitmapIndex = sdci[2]/10000;
6527 266215 int32_t usr_bitmap_index = sdci[2];
6528
1/2
✓ Branch 0 taken 266215 times.
✗ Branch 1 not taken.
266215 if ( bitmapIndex > 10000 )
6529 {
6530 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6531 }
6532
3/4
✓ Branch 0 taken 172226 times.
✓ Branch 1 taken 93989 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 172226 times.
266215 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
6533 {
6534 172226 bitmapIndex = usr_bitmap_index;
6535 172226 yoffset = 0;
6536 172226 }
6537
6538 266215 int32_t sx = sdci[3]/10000;
6539 266215 int32_t sy = sdci[4]/10000;
6540 266215 int32_t sw = sdci[5]/10000;
6541 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
6542 266215 int32_t sh = sdci[6]/10000;
6543 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
6544 266215 int32_t dx = sdci[7]/10000;
6545 266215 int32_t dy = sdci[8]/10000;
6546 266215 int32_t dw = sdci[9]/10000;
6547 266215 int32_t dh = sdci[10]/10000;
6548 266215 float rot = sdci[11]/10000;
6549 266215 int32_t cx = sdci[12]/10000;
6550 266215 int32_t cy = sdci[13]/10000;
6551 266215 int32_t mode = sdci[14]/10000;
6552 266215 int32_t litcolour = sdci[15]/10000;
6553 266215 bool masked = (sdci[16] != 0);
6554
6555 266215 int32_t ref = 0;
6556
6557 266215 dx = dx + xoffset;
6558 266215 dy = dy + yoffset;
6559
6560
2/4
✓ Branch 0 taken 266215 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 266215 times.
266215 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
6561 //Do we need to also check the render target and do the same thing if the
6562 //dest == -2 and the render target is not RT_SCREEN?
6563
6564 266215 ref = sdci[17];
6565
6566
6567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 266215 times.
266215 if ( ref <= 0 )
6568 {
6569 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6570 return;
6571 }
6572 266215 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6573
6574
1/2
✓ Branch 0 taken 266215 times.
✗ Branch 1 not taken.
266215 if(!sourceBitmap)
6575 {
6576
6577 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
6578 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6579 return;
6580 }
6581
6582 266215 BITMAP *destBMP=NULL;
6583 //zprint2("blit () bitmap index is: %d\n",bitmapIndex);
6584
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 172226 times.
✓ Branch 2 taken 786 times.
✓ Branch 3 taken 93203 times.
266215 switch(bitmapIndex)
6585 {
6586 case -2:
6587 {
6588 786 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6589 //zprint2("current RT is: %d\n", curr_rt);
6590
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
786 if ( curr_rt >= 0 && curr_rt < 7 )
6591 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6592 786 else destBMP = bmp; //screen
6593 786 break;
6594 }
6595 case -1:
6596 93203 destBMP = bmp; //this is framebuf, by default
6597 93203 break;
6598 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6599 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6600 //destBMP = framebuf; //Drawing to the screen.
6601 //break;
6602
6603 //1 through 6 are the old system bitmaps (Render Targets)
6604 case 0:
6605 case 1:
6606 case 2:
6607 case 3:
6608 case 4:
6609 case 5:
6610 case 6:
6611 {
6612 //This gets a render target.
6613 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6614
6615 //destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6616 //sdci[18] = bitmapIndex;
6617 break;
6618 }
6619 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6620 default:
6621 {
6622 172226 auto& usr_bitmap = scb.get(usr_bitmap_index);
6623 172226 destBMP = usr_bitmap.u_bmp;
6624 //sdci[18] = usr_bitmap_index;
6625
1/2
✓ Branch 0 taken 172226 times.
✗ Branch 1 not taken.
172226 if ( !usr_bitmap.u_bmp )
6626 {
6627 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
6628 break;
6629 }
6630 }
6631 172226 }
6632
6633
1/2
✓ Branch 0 taken 266215 times.
✗ Branch 1 not taken.
266215 if (!destBMP)
6634 {
6635 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6636 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6637 return;
6638 }
6639
6640
2/2
✓ Branch 0 taken 1027 times.
✓ Branch 1 taken 265188 times.
266215 bool stretched = (sw != dw || sh != dh);
6641 266215 BITMAP* subBmp = 0;
6642
6643
4/4
✓ Branch 0 taken 264636 times.
✓ Branch 1 taken 1579 times.
✓ Branch 2 taken 24983 times.
✓ Branch 3 taken 239653 times.
266215 if(rot != 0 || mode != 0)
6644 {
6645 26562 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
6646 26562 clear_bitmap(subBmp);
6647
6648
1/2
✓ Branch 0 taken 26562 times.
✗ Branch 1 not taken.
26562 if(!subBmp)
6649 {
6650
6651 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
6652 return;
6653 }
6654 26562 }
6655 266215 BITMAP* sbmp = sourceBitmap;
6656
2/4
✓ Branch 0 taken 266215 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 266215 times.
266215 if (sx + sw > sbmp->w || sy + sh > sbmp->h)
6657 {
6658 sbmp = create_bitmap_ex(8, sw, sh);
6659 clear_bitmap(sbmp);
6660 blit(sourceBitmap, sbmp, sx, sy, 0, 0, std::min(sourceBitmap->w-sx, sw), std::min(sourceBitmap->h-sy, sh));
6661 sx = 0;
6662 sy = 0;
6663 }
6664 //dx = dx + xoffset; //don't do this here!
6665 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6666
6667
2/2
✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 264613 times.
266215 if(stretched)
6668 {
6669
2/2
✓ Branch 0 taken 1475 times.
✓ Branch 1 taken 127 times.
1602 if(masked)
6670 { //stretched and masked
6671
2/2
✓ Branch 0 taken 574 times.
✓ Branch 1 taken 901 times.
1475 if ( rot == 0 )
6672 { //if not rotated
6673
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
901 switch(mode)
6674 {
6675 case 1:
6676 //transparent
6677 900 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6678 900 draw_trans_sprite(destBMP, subBmp, dx, dy);
6679 900 break;
6680
6681
6682 case 2:
6683 //pivot?
6684 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6685 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6686 //Pivoting requires two more args
6687 break;
6688
6689 case 3:
6690 //pivot + trans
6691 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6692 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6693 break;
6694
6695 case 4:
6696 //flip v
6697 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6698 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6699 break;
6700
6701 case 5:
6702 //trans + v flip
6703 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6704 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6705 break;
6706
6707 case 6:
6708 //pivot + v flip
6709 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6710 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6711 break;
6712
6713 case 8:
6714 //vlip h
6715 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6716 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6717 break;
6718
6719 case 9:
6720 //trans + h flip
6721 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6722 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6723 break;
6724
6725 case 10:
6726 //flip H and pivot
6727 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6728 //return error cannot pivot and h flip
6729 break;
6730
6731 case 12:
6732 //vh flip
6733 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6734 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6735 break;
6736
6737 case 13:
6738 //trans + vh flip
6739 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6740 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6741 break;
6742
6743 case 14:
6744 //pivot and vh flip
6745 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6746 //return error cannot both pivot and vh flip
6747 break;
6748
6749 case 16:
6750 //lit
6751 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6752 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6753 break;
6754
6755 case 18:
6756 //pivot, lit
6757 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6758 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6759 break;
6760
6761 case 20:
6762 //lit + v flip
6763 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6764 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6765 break;
6766
6767 case 22:
6768 //Pivot, vflip, lit
6769 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6770 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6771 break;
6772
6773 case 24:
6774 //lit + h flip
6775 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6776 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6777 break;
6778
6779 case 26:
6780 //pivot + lit + hflip
6781 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
6782 //return error cannot pivot, lit, and flip
6783 break;
6784
6785 case 28:
6786 //lit + vh flip
6787 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6788 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
6789 break;
6790
6791 case 32: //gouraud
6792 //Probably not wort supporting.
6793 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6794 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6795 break;
6796
6797 case 0:
6798 //no effect
6799 1 masked_stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
6800 1 break;
6801
6802
6803 default:
6804
6805 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6806
6807
6808 }
6809 901 } //end if not rotated
6810
6811
2/2
✓ Branch 0 taken 901 times.
✓ Branch 1 taken 574 times.
1475 if ( rot != 0 ) //if rotated
6812 {
6813
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 574 times.
✗ Branch 21 not taken.
574 switch(mode)
6814 {
6815 case 1:
6816 //transparent
6817 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6818 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6819
6820 break;
6821
6822 case 2:
6823 //pivot?
6824 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6825 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6826 //Pivoting requires two more args
6827 break;
6828
6829 case 3:
6830 //pivot + trans
6831 //return an error, cannot both rotate and pivot
6832 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6833 break;
6834
6835 case 4:
6836 //flip v
6837 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6838 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6839 break;
6840
6841 case 5:
6842 //trans + v flip
6843 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6844 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6845 break;
6846
6847 case 6:
6848 //pivot + v flip
6849 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6850 //return an error, cannot both rotate and pivot
6851 break;
6852
6853 case 8:
6854 //flip h
6855 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
6856 //return an error, cannot both rotate and flip H
6857 break;
6858
6859 case 9:
6860 //trans + h flip
6861 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
6862 //return an error, cannot rotate and flip a trans sprite
6863 break;
6864
6865 case 10:
6866 //flip H and pivot
6867 //return error cannot pivot and h flip
6868 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6869 break;
6870
6871 case 12:
6872 //vh flip
6873 //return an error, cannot rotate and VH flip a trans sprite
6874 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6875 break;
6876
6877 case 13:
6878 //trans + vh flip
6879 //return an error, cannot rotate and VH flip a trans sprite
6880 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6881 break;
6882
6883 case 14:
6884 //pivot and vh flip
6885 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6886 //return error cannot both pivot and vh flip
6887 break;
6888
6889 case 16:
6890 //lit
6891 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6892 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6893 break;
6894
6895 case 18:
6896 //pivot, lit
6897 //return an error, cannot both rotate and pivot
6898 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6899 break;
6900
6901 case 20:
6902 //lit + vflip
6903 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6904 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6905 break;
6906
6907 case 22:
6908 //Pivot, vflip, lit
6909 //return an error, cannot both rotate and pivot
6910 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6911 break;
6912
6913 case 24:
6914 //lit + h flip
6915 //return an error, cannot both rotate and H flip
6916 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
6917 break;
6918
6919 case 26:
6920 //pivot + lit + hflip
6921 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
6922 //return error cannot pivot, lit, and flip
6923 break;
6924
6925 case 28:
6926 //lit + vh flip
6927 //return an error, cannot both rotate and VH flip
6928 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6929 break;
6930
6931 case 32: //gouraud
6932 //Probably not wort supporting.
6933 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6934 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6935 break;
6936
6937 case 0:
6938 //no effect.
6939 574 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6940 574 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6941 574 break;
6942
6943 default:
6944
6945 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6946
6947 }
6948 574 }
6949 1475 } //end if stretched and masked
6950
6951 else //stretched, not masked
6952 {
6953
6954
6955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( rot == 0 ) //if not rotated
6956 {
6957
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 127 times.
127 switch(mode)
6958 {
6959 case 1:
6960 //transparent
6961 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6962 draw_trans_sprite(destBMP, subBmp, dx, dy);
6963 break;
6964
6965
6966 case 2:
6967 //pivot?
6968 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6969 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6970 //Pivoting requires two more args
6971 break;
6972
6973 case 3:
6974 //pivot + trans
6975 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6976 pivot_sprite_trans(destBMP, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
6977 break;
6978
6979 case 4:
6980 //flip v
6981 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6982 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6983 break;
6984
6985 case 5:
6986 //trans + v flip
6987 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6988 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6989 break;
6990
6991 case 6:
6992 //pivot + v flip
6993 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6994 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6995 break;
6996
6997 case 8:
6998 //vlip h
6999 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7000 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7001 break;
7002
7003 case 9:
7004 //trans + h flip
7005 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7006 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7007 break;
7008
7009 case 10:
7010 //flip H and pivot
7011 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7012 //return error cannot pivot and h flip
7013 break;
7014
7015 case 12:
7016 //vh flip
7017 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7018 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7019 break;
7020
7021 case 13:
7022 //trans + vh flip
7023 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7024 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7025 break;
7026
7027 case 14:
7028 //pivot and vh flip
7029 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7030 //return error cannot both pivot and vh flip
7031 break;
7032
7033 case 16:
7034 //lit
7035 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7036 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7037 break;
7038
7039 case 18:
7040 //pivot, lit
7041 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7042 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7043 break;
7044
7045 case 20:
7046 //lit + v flip
7047 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7048 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7049 break;
7050
7051 case 22:
7052 //Pivot, vflip, lit
7053 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7054 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7055 break;
7056
7057 case 24:
7058 //lit + h flip
7059 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7060 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7061 break;
7062
7063 case 26:
7064 //pivot + lit + hflip
7065 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7066 //return error cannot pivot, lit, and flip
7067 break;
7068
7069 case 28:
7070 //lit + vh flip
7071 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7072 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7073 break;
7074
7075 case 32: //gouraud
7076 //Probably not wort supporting.
7077 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7078 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7079 break;
7080
7081 case 0:
7082 //no effect
7083 127 stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
7084 127 break;
7085
7086
7087 default:
7088
7089 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7090
7091
7092 }
7093 127 } //end if not rotated
7094
7095
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if ( rot != 0 ) //if rotated
7096 {
7097 switch(mode)
7098 {
7099 case 1:
7100 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7101 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7102
7103 break;
7104
7105 case 2:
7106 //pivot?
7107 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7108 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7109 //Pivoting requires two more args
7110 break;
7111
7112 case 3:
7113 //pivot + trans
7114 //return an error, cannot both rotate and pivot
7115 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7116 break;
7117
7118 case 4:
7119 //flip v
7120 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7121 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7122 break;
7123
7124 case 5:
7125 //trans + v flip
7126 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7127 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7128 break;
7129
7130 case 6:
7131 //pivot + v flip
7132 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7133 //return an error, cannot both rotate and pivot
7134 break;
7135
7136 case 8:
7137 //flip h
7138 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7139 //return an error, cannot both rotate and flip H
7140 break;
7141
7142 case 9:
7143 //trans + h flip
7144 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7145 //return an error, cannot rotate and flip a trans sprite
7146 break;
7147
7148 case 10:
7149 //flip H and pivot
7150 //return error cannot pivot and h flip
7151 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7152 break;
7153
7154 case 12:
7155 //vh flip
7156 //return an error, cannot rotate and VH flip a trans sprite
7157 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7158 break;
7159
7160 case 13:
7161 //trans + vh flip
7162 //return an error, cannot rotate and VH flip a trans sprite
7163 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7164 break;
7165
7166 case 14:
7167 //pivot and vh flip
7168 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7169 //return error cannot both pivot and vh flip
7170 break;
7171
7172 case 16:
7173 //lit
7174 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7175 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7176 break;
7177
7178 case 18:
7179 //pivot, lit
7180 //return an error, cannot both rotate and pivot
7181 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7182 break;
7183
7184 case 20:
7185 //lit + vflip
7186 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7187 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7188 break;
7189
7190 case 22:
7191 //Pivot, vflip, lit
7192 //return an error, cannot both rotate and pivot
7193 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7194 break;
7195
7196 case 24:
7197 //lit + h flip
7198 //return an error, cannot both rotate and H flip
7199 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7200 break;
7201
7202 case 26:
7203 //pivot + lit + hflip
7204 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7205 //return error cannot pivot, lit, and flip
7206 break;
7207
7208 case 28:
7209 //lit + vh flip
7210 //return an error, cannot both rotate and VH flip
7211 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7212 break;
7213
7214 case 32: //gouraud
7215 //Probably not wort supporting.
7216 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7217 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7218 break;
7219
7220 case 0:
7221 //no effect.
7222 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7223 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7224 break;
7225
7226 default:
7227
7228 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7229
7230 }
7231 }
7232
7233 } //end if stretched, but not masked
7234 1602 }
7235 else //not stretched
7236 {
7237
7238
2/2
✓ Branch 0 taken 253627 times.
✓ Branch 1 taken 10986 times.
264613 if(masked) //if masked, but not stretched
7239 {
7240
7241
2/2
✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 252622 times.
253627 if ( rot == 0 ) //if not rotated
7242 {
7243
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 18689 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 233933 times.
252622 switch(mode)
7244 {
7245 case 1:
7246 //transparent
7247 18689 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7248 18689 draw_trans_sprite(destBMP, subBmp, dx, dy);
7249 18689 break;
7250
7251
7252 case 2:
7253 //pivot?
7254 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7255 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7256 //Pivoting requires two more args
7257 break;
7258
7259 case 3:
7260 //pivot + trans
7261 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7262 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7263 break;
7264
7265 case 4:
7266 //flip v
7267 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7268 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7269 break;
7270
7271 case 5:
7272 //trans + v flip
7273 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7274 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7275 break;
7276
7277 case 6:
7278 //pivot + v flip
7279 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7280 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7281 break;
7282
7283 case 8:
7284 //vlip h
7285 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7286 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7287 break;
7288
7289 case 9:
7290 //trans + h flip
7291 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7292 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7293 break;
7294
7295 case 10:
7296 //flip H and pivot
7297 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7298 //return error cannot pivot and h flip
7299 break;
7300
7301 case 12:
7302 //vh flip
7303 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7304 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7305 break;
7306
7307 case 13:
7308 //trans + vh flip
7309 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7310 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7311 break;
7312
7313 case 14:
7314 //pivot and vh flip
7315 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7316 //return error cannot both pivot and vh flip
7317 break;
7318
7319 case 16:
7320 //lit
7321 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7322 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7323 break;
7324
7325 case 18:
7326 //pivot, lit
7327 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7328 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7329 break;
7330
7331 case 20:
7332 //lit + v flip
7333 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7334 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7335 break;
7336
7337 case 22:
7338 //Pivot, vflip, lit
7339 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7340 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7341 break;
7342
7343 case 24:
7344 //lit + h flip
7345 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7346 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7347 break;
7348
7349 case 26:
7350 //pivot + lit + hflip
7351 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7352 //return error cannot pivot, lit, and flip
7353 break;
7354
7355 case 28:
7356 //lit + vh flip
7357 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7358 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7359 break;
7360
7361 case 32: //gouraud
7362 //Probably not wort supporting.
7363 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7364 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7365 break;
7366
7367 case 0:
7368 //no effect
7369 233933 masked_blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7370 233933 break;
7371
7372
7373 default:
7374
7375 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7376
7377
7378 }
7379 252622 } //end if not rotated
7380
7381
2/2
✓ Branch 0 taken 252622 times.
✓ Branch 1 taken 1005 times.
253627 if ( rot != 0 ) //if rotated
7382 {
7383
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 1005 times.
✗ Branch 21 not taken.
1005 switch(mode)
7384 {
7385 case 1:
7386 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
7387 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7388
7389 break;
7390
7391 case 2:
7392 //pivot?
7393 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7394 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7395 //Pivoting requires two more args
7396 break;
7397
7398 case 3:
7399 //pivot + trans
7400 //return an error, cannot both rotate and pivot
7401 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7402 break;
7403
7404 case 4:
7405 //flip v
7406 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7407 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7408 break;
7409
7410 case 5:
7411 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
7412 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7413 break;
7414
7415 case 6:
7416 //pivot + v flip
7417 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7418 //return an error, cannot both rotate and pivot
7419 break;
7420
7421 case 8:
7422 //flip h
7423 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7424 //return an error, cannot both rotate and flip H
7425 break;
7426
7427 case 9:
7428 //trans + h flip
7429 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7430 //return an error, cannot rotate and flip a trans sprite
7431 break;
7432
7433 case 10:
7434 //flip H and pivot
7435 //return error cannot pivot and h flip
7436 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7437 break;
7438
7439 case 12:
7440 //vh flip
7441 //return an error, cannot rotate and VH flip a trans sprite
7442 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7443 break;
7444
7445 case 13:
7446 //trans + vh flip
7447 //return an error, cannot rotate and VH flip a trans sprite
7448 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7449 break;
7450
7451 case 14:
7452 //pivot and vh flip
7453 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7454 //return error cannot both pivot and vh flip
7455 break;
7456
7457 case 16:
7458 //lit
7459 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7460 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7461 break;
7462
7463 case 18:
7464 //pivot, lit
7465 //return an error, cannot both rotate and pivot
7466 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7467 break;
7468
7469 case 20:
7470 //lit + vflip
7471 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7472 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7473 break;
7474
7475 case 22:
7476 //Pivot, vflip, lit
7477 //return an error, cannot both rotate and pivot
7478 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7479 break;
7480
7481 case 24:
7482 //lit + h flip
7483 //return an error, cannot both rotate and H flip
7484 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7485 break;
7486
7487 case 26:
7488 //pivot + lit + hflip
7489 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7490 //return error cannot pivot, lit, and flip
7491 break;
7492
7493 case 28:
7494 //lit + vh flip
7495 //return an error, cannot both rotate and VH flip
7496 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7497 break;
7498
7499 case 32: //gouraud
7500 //Probably not wort supporting.
7501 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7502 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7503 break;
7504
7505 case 0:
7506 //no effect.
7507 1005 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7508 1005 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7509 1005 break;
7510
7511 default:
7512
7513 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7514
7515 }
7516 1005 } //end rtated, masked
7517 253627 } //end if masked
7518
7519 else //not masked, and not stretched; just blit
7520 {
7521
7522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10986 times.
10986 if ( rot == 0 ) //if not rotated
7523 {
7524
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 5394 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5592 times.
10986 switch(mode)
7525 {
7526 case 1:
7527 //transparent
7528 5394 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7529 5394 draw_trans_sprite(destBMP, subBmp, dx, dy);
7530 5394 break;
7531
7532
7533 case 2:
7534 //pivot?
7535 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7536 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7537 //Pivoting requires two more args
7538 break;
7539
7540 case 3:
7541 //pivot + trans
7542 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7543 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7544 break;
7545
7546 case 4:
7547 //flip v
7548 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7549 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7550 break;
7551
7552 case 5:
7553 //trans + v flip
7554 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7555 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7556 break;
7557
7558 case 6:
7559 //pivot + v flip
7560 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7561 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7562 break;
7563
7564 case 8:
7565 //vlip h
7566 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7567 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7568 break;
7569
7570 case 9:
7571 //trans + h flip
7572 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7573 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7574 break;
7575
7576 case 10:
7577 //flip H and pivot
7578 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7579 //return error cannot pivot and h flip
7580 break;
7581
7582 case 12:
7583 //vh flip
7584 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7585 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7586 break;
7587
7588 case 13:
7589 //trans + vh flip
7590 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7591 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7592 break;
7593
7594 case 14:
7595 //pivot and vh flip
7596 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7597 //return error cannot both pivot and vh flip
7598 break;
7599
7600 case 16:
7601 //lit
7602 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7603 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7604 break;
7605
7606 case 18:
7607 //pivot, lit
7608 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7609 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7610 break;
7611
7612 case 20:
7613 //lit + v flip
7614 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7615 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7616 break;
7617
7618 case 22:
7619 //Pivot, vflip, lit
7620 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7621 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7622 break;
7623
7624 case 24:
7625 //lit + h flip
7626 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7627 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7628 break;
7629
7630 case 26:
7631 //pivot + lit + hflip
7632 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7633 //return error cannot pivot, lit, and flip
7634 break;
7635
7636 case 28:
7637 //lit + vh flip
7638 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7639 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7640 break;
7641
7642 case 32: //gouraud
7643 //Probably not wort supporting.
7644 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7645 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7646 break;
7647
7648 case 0:
7649 //no effect
7650 5592 blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7651 5592 break;
7652
7653
7654 default:
7655
7656 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7657
7658
7659 }
7660 10986 } //end if not rotated
7661
7662
1/2
✓ Branch 0 taken 10986 times.
✗ Branch 1 not taken.
10986 if ( rot != 0 ) //if rotated
7663 {
7664 switch(mode)
7665 {
7666 case 1:
7667 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
7668 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7669
7670 break;
7671
7672 case 2:
7673 //pivot?
7674 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7675 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7676 //Pivoting requires two more args
7677 break;
7678
7679 case 3:
7680 //pivot + trans
7681 //return an error, cannot both rotate and pivot
7682 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7683 break;
7684
7685 case 4:
7686 //flip v
7687 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7688 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7689 break;
7690
7691 case 5:
7692 //trans + v flip
7693 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7694 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7695 break;
7696
7697 case 6:
7698 //pivot + v flip
7699 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7700 //return an error, cannot both rotate and pivot
7701 break;
7702
7703 case 8:
7704 //flip h
7705 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7706 //return an error, cannot both rotate and flip H
7707 break;
7708
7709 case 9:
7710 //trans + h flip
7711 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7712 //return an error, cannot rotate and flip a trans sprite
7713 break;
7714
7715 case 10:
7716 //flip H and pivot
7717 //return error cannot pivot and h flip
7718 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7719 break;
7720
7721 case 12:
7722 //vh flip
7723 //return an error, cannot rotate and VH flip a trans sprite
7724 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7725 break;
7726
7727 case 13:
7728 //trans + vh flip
7729 //return an error, cannot rotate and VH flip a trans sprite
7730 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7731 break;
7732
7733 case 14:
7734 //pivot and vh flip
7735 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7736 //return error cannot both pivot and vh flip
7737 break;
7738
7739 case 16:
7740 //lit
7741 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7742 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7743 break;
7744
7745 case 18:
7746 //pivot, lit
7747 //return an error, cannot both rotate and pivot
7748 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7749 break;
7750
7751 case 20:
7752 //lit + vflip
7753 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7754 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7755 break;
7756
7757 case 22:
7758 //Pivot, vflip, lit
7759 //return an error, cannot both rotate and pivot
7760 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7761 break;
7762
7763 case 24:
7764 //lit + h flip
7765 //return an error, cannot both rotate and H flip
7766 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7767 break;
7768
7769 case 26:
7770 //pivot + lit + hflip
7771 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7772 //return error cannot pivot, lit, and flip
7773 break;
7774
7775 case 28:
7776 //lit + vh flip
7777 //return an error, cannot both rotate and VH flip
7778 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7779 break;
7780
7781 case 32: //gouraud
7782 //Probably not wort supporting.
7783 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7784 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7785 break;
7786
7787 case 0:
7788 //no effect.
7789 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7790 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7791 break;
7792
7793 default:
7794
7795 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7796
7797 }
7798 } //end if rotated
7799 } //end if not masked
7800 } //end if not stretched
7801
7802 //cleanup
7803
2/2
✓ Branch 0 taken 26562 times.
✓ Branch 1 taken 239653 times.
266215 if(subBmp)
7804 {
7805 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
7806 26562 destroy_bitmap(subBmp);
7807 26562 }
7808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 266215 times.
266215 if (sbmp != sourceBitmap)
7809 {
7810 destroy_bitmap(sbmp);
7811 }
7812 266215 }
7813
7814
7815
7816 113329 void bmp_do_blittor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
7817 {
7818 /*
7819 //sdci[1]=layer
7820 //sdci[2]=bitmap target
7821 //
7822 // -2 is the current Render Target
7823 // -1, this is the screen (framebuf).
7824 // 0: Render target 0
7825 // 1: Render target 1
7826 // 2: Render target 2
7827 // 3: Render target 3
7828 // 4: Render target 4
7829 // 5: Render target 5
7830 // 6: Render target 6
7831 // Otherwise: The pointer to a bitmap.
7832
7833 //sdci[3]=sourcex
7834 //sdci[4]=sourcey
7835 //sdci[5]=sourcew
7836 //sdci[6]=sourceh
7837 //sdci[7]=destx
7838 //sdci[8]=desty
7839 //sdci[9]=destw
7840 //sdci[10]=desth
7841 //sdci[11]=rotation/angle
7842 //scdi[12] = pivot cx
7843 //sdci[13] = pivot cy
7844 //scdi[14] = effect flags
7845 //sdci[17] Bitmap Pointer
7846
7847 // ZScript-side constant values:
7848 const int32_t BITDX_NORMAL = 0;
7849 const int32_t BITDX_TRANS = 1; //Translucent
7850 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
7851 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
7852 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
7853 //Note: Some modes cannot be combined. if a combination is not supported, an error
7854 // detailing this will be shown in allegro.log.
7855
7856 //scdi[15] = litcolour
7857 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7858 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
7859
7860 //sdci[16]=mask
7861
7862 */
7863
7864 113329 int32_t srcyoffset = yoffset, srcxoffset = xoffset;
7865 113329 int32_t bitmapIndex = sdci[2]/10000;
7866 113329 int32_t usr_bitmap_index = sdci[2];
7867
7868
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if ( bitmapIndex > 10000 )
7869 {
7870 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
7871 }
7872
3/4
✓ Branch 0 taken 113326 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 113326 times.
113329 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
7873 {
7874 113326 bitmapIndex = usr_bitmap_index;
7875 113326 srcyoffset = 0;
7876 113326 }
7877
7878 113329 int32_t sx = sdci[3]/10000;
7879 113329 int32_t sy = sdci[4]/10000;
7880 113329 int32_t sw = sdci[5]/10000;
7881 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
7882 113329 int32_t sh = sdci[6]/10000;
7883 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
7884 113329 int32_t dx = sdci[7]/10000;
7885 113329 int32_t dy = sdci[8]/10000;
7886 113329 int32_t dw = sdci[9]/10000;
7887 113329 int32_t dh = sdci[10]/10000;
7888 113329 float rot = sdci[11]/10000;
7889 113329 int32_t cx = sdci[12]/10000;
7890 113329 int32_t cy = sdci[13]/10000;
7891 113329 int32_t mode = sdci[14]/10000;
7892 113329 int32_t litcolour = sdci[15]/10000;
7893 113329 bool masked = (sdci[16] != 0);
7894
7895 113329 int32_t ref = 0;
7896
7897 //These should go down farther, should they not? -V
7898 //dx = dx + xoffset;
7899 //dy = dy + yoffset;
7900
7901
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
7902
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if ( (bitmapIndex) != -2 && (bitmapIndex) != -1 ) srcyoffset = 0; //Don't crop.
7903 //Do we need to also check the render target and do the same thing if the
7904 //dest == -2 and the render target is not RT_SCREEN?
7905 113329 dx = dx + xoffset;
7906 113329 dy = dy + yoffset;
7907 113329 sx = sx + srcxoffset;
7908 113329 sy = sy + srcyoffset;
7909
7910 113329 ref = sdci[17];
7911
7912
7913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if ( ref <= 0 )
7914 {
7915 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
7916 return;
7917 }
7918 113329 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
7919
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if(!sourceBitmap)
7920 {
7921 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
7922 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7923 return;
7924 }
7925
7926 113329 BITMAP *destBMP=NULL;
7927 //zprint2("RevBlit bitmap index is: %d\n",bitmapIndex);
7928
7929
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
113329 switch(bitmapIndex)
7930 {
7931 case -2:
7932 {
7933 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
7934 //zprint2("current RT is: %d\n", curr_rt);
7935 if ( curr_rt >= 0 && curr_rt < 7 )
7936 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
7937 else destBMP = bmp; //screen
7938 break;
7939 }
7940 case -1:
7941 3 destBMP = bmp; //this is framebuf, by default
7942 3 break;
7943 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
7944 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
7945 //destBMP = framebuf; //Drawing to the screen.
7946 //break;
7947
7948 //1 through 6 are the old system bitmaps (Render Targets)
7949 case 0:
7950 case 1:
7951 case 2:
7952 case 3:
7953 case 4:
7954 case 5:
7955 case 6:
7956 {
7957 //This gets a render target.
7958 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
7959
7960 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
7961 //sdci[18] = bitmapIndex;
7962 break;
7963 }
7964 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
7965 default:
7966 {
7967 113326 auto& usr_bitmap = scb.get(usr_bitmap_index);
7968 113326 destBMP = usr_bitmap.u_bmp;
7969 //sdci[18] = usr_bitmap_index;
7970
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( !usr_bitmap.u_bmp )
7971 {
7972 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
7973 break;
7974 }
7975 }
7976 113326 }
7977
7978
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (!destBMP)
7979 {
7980 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
7981 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7982 return;
7983 }
7984
7985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 bool stretched = (sw != dw || sh != dh);
7986
7987 113329 BITMAP* newDest = sourceBitmap;
7988 113329 BITMAP* newSource = destBMP; //Flip them.
7989
7990 113329 BITMAP* subBmp = 0;
7991
7992
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if(rot != 0 || mode != 0)
7993 {
7994 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
7995 clear_bitmap(subBmp);
7996
7997 if(!subBmp)
7998 {
7999 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
8000 return;
8001 }
8002 }
8003
8004
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if (sx + sw > destBMP->w || sy + sh > destBMP->h)
8005 {
8006 3 newSource = create_bitmap_ex(8, sw, sh);
8007 3 clear_bitmap(newSource);
8008 3 blit(destBMP, newSource, sx, sy, 0, 0, std::min(destBMP->w-sx, sw), std::min(destBMP->h-sy, sh));
8009 3 sx = 0;
8010 3 sy = 0;
8011 3 }
8012 //dx = dx + xoffset; //don't do this here!
8013 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
8014
8015
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(stretched)
8016 {
8017 if(masked)
8018 { //stretched and masked
8019 if ( rot == 0 )
8020 { //if not rotated
8021 switch(mode)
8022 {
8023 case 1:
8024 //transparent
8025 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8026 draw_trans_sprite(newDest, subBmp, dx, dy);
8027 break;
8028
8029
8030 case 2:
8031 //pivot?
8032 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8033 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8034 //Pivoting requires two more args
8035 break;
8036
8037 case 3:
8038 //pivot + trans
8039 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8040 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8041 break;
8042
8043 case 4:
8044 //flip v
8045 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8046 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8047 break;
8048
8049 case 5:
8050 //trans + v flip
8051 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8052 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8053 break;
8054
8055 case 6:
8056 //pivot + v flip
8057 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8058 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8059 break;
8060
8061 case 8:
8062 //vlip h
8063 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8064 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8065 break;
8066
8067 case 9:
8068 //trans + h flip
8069 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8070 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8071 break;
8072
8073 case 10:
8074 //flip H and pivot
8075 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8076 //return error cannot pivot and h flip
8077 break;
8078
8079 case 12:
8080 //vh flip
8081 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8082 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8083 break;
8084
8085 case 13:
8086 //trans + vh flip
8087 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8088 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8089 break;
8090
8091 case 14:
8092 //pivot and vh flip
8093 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8094 //return error cannot both pivot and vh flip
8095 break;
8096
8097 case 16:
8098 //lit
8099 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8100 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8101 break;
8102
8103 case 18:
8104 //pivot, lit
8105 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8106 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8107 break;
8108
8109 case 20:
8110 //lit + v flip
8111 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8112 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8113 break;
8114
8115 case 22:
8116 //Pivot, vflip, lit
8117 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8118 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8119 break;
8120
8121 case 24:
8122 //lit + h flip
8123 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8124 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8125 break;
8126
8127 case 26:
8128 //pivot + lit + hflip
8129 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8130 //return error cannot pivot, lit, and flip
8131 break;
8132
8133 case 28:
8134 //lit + vh flip
8135 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8136 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8137 break;
8138
8139 case 32: //gouraud
8140 //Probably not wort supporting.
8141 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8142 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8143 break;
8144
8145 case 0:
8146 //no effect
8147 masked_stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8148 break;
8149
8150
8151 default:
8152 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8153
8154
8155 }
8156 } //end if not rotated
8157
8158 if ( rot != 0 ) //if rotated
8159 {
8160 switch(mode)
8161 {
8162 case 1:
8163 //transparent
8164 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8165 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8166
8167 break;
8168
8169 case 2:
8170 //pivot?
8171 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8172 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8173 //Pivoting requires two more args
8174 break;
8175
8176 case 3:
8177 //pivot + trans
8178 //return an error, cannot both rotate and pivot
8179 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8180 break;
8181
8182 case 4:
8183 //flip v
8184 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8185 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8186 break;
8187
8188 case 5:
8189 //trans + v flip
8190 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8191 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8192 break;
8193
8194 case 6:
8195 //pivot + v flip
8196 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8197 //return an error, cannot both rotate and pivot
8198 break;
8199
8200 case 8:
8201 //flip h
8202 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8203 //return an error, cannot both rotate and flip H
8204 break;
8205
8206 case 9:
8207 //trans + h flip
8208 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8209 //return an error, cannot rotate and flip a trans sprite
8210 break;
8211
8212 case 10:
8213 //flip H and pivot
8214 //return error cannot pivot and h flip
8215 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8216 break;
8217
8218 case 12:
8219 //vh flip
8220 //return an error, cannot rotate and VH flip a trans sprite
8221 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8222 break;
8223
8224 case 13:
8225 //trans + vh flip
8226 //return an error, cannot rotate and VH flip a trans sprite
8227 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8228 break;
8229
8230 case 14:
8231 //pivot and vh flip
8232 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8233 //return error cannot both pivot and vh flip
8234 break;
8235
8236 case 16:
8237 //lit
8238 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8239 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8240 break;
8241
8242 case 18:
8243 //pivot, lit
8244 //return an error, cannot both rotate and pivot
8245 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8246 break;
8247
8248 case 20:
8249 //lit + vflip
8250 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8251 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8252 break;
8253
8254 case 22:
8255 //Pivot, vflip, lit
8256 //return an error, cannot both rotate and pivot
8257 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8258 break;
8259
8260 case 24:
8261 //lit + h flip
8262 //return an error, cannot both rotate and H flip
8263 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8264 break;
8265
8266 case 26:
8267 //pivot + lit + hflip
8268 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8269 //return error cannot pivot, lit, and flip
8270 break;
8271
8272 case 28:
8273 //lit + vh flip
8274 //return an error, cannot both rotate and VH flip
8275 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8276 break;
8277
8278 case 32: //gouraud
8279 //Probably not wort supporting.
8280 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8281 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8282 break;
8283
8284 case 0:
8285 //no effect.
8286 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8287 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8288 break;
8289
8290 default:
8291 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8292
8293 }
8294 }
8295 } //end if stretched and masked
8296
8297 else //stretched, not masked
8298 {
8299
8300
8301 if ( rot == 0 ) //if not rotated
8302 {
8303 switch(mode)
8304 {
8305 case 1:
8306 //transparent
8307 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8308 draw_trans_sprite(newDest, subBmp, dx, dy);
8309 break;
8310
8311
8312 case 2:
8313 //pivot?
8314 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8315 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8316 //Pivoting requires two more args
8317 break;
8318
8319 case 3:
8320 //pivot + trans
8321 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8322 pivot_sprite_trans(newDest, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
8323 break;
8324
8325 case 4:
8326 //flip v
8327 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8328 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8329 break;
8330
8331 case 5:
8332 //trans + v flip
8333 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8334 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8335 break;
8336
8337 case 6:
8338 //pivot + v flip
8339 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8340 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8341 break;
8342
8343 case 8:
8344 //vlip h
8345 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8346 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8347 break;
8348
8349 case 9:
8350 //trans + h flip
8351 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8352 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8353 break;
8354
8355 case 10:
8356 //flip H and pivot
8357 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8358 //return error cannot pivot and h flip
8359 break;
8360
8361 case 12:
8362 //vh flip
8363 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8364 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8365 break;
8366
8367 case 13:
8368 //trans + vh flip
8369 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8370 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8371 break;
8372
8373 case 14:
8374 //pivot and vh flip
8375 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8376 //return error cannot both pivot and vh flip
8377 break;
8378
8379 case 16:
8380 //lit
8381 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8382 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8383 break;
8384
8385 case 18:
8386 //pivot, lit
8387 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8388 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8389 break;
8390
8391 case 20:
8392 //lit + v flip
8393 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8394 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8395 break;
8396
8397 case 22:
8398 //Pivot, vflip, lit
8399 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8400 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8401 break;
8402
8403 case 24:
8404 //lit + h flip
8405 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8406 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8407 break;
8408
8409 case 26:
8410 //pivot + lit + hflip
8411 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8412 //return error cannot pivot, lit, and flip
8413 break;
8414
8415 case 28:
8416 //lit + vh flip
8417 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8418 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8419 break;
8420
8421 case 32: //gouraud
8422 //Probably not wort supporting.
8423 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8424 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8425 break;
8426
8427 case 0:
8428 //no effect
8429 stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8430 break;
8431
8432
8433 default:
8434 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8435
8436
8437 }
8438 } //end if not rotated
8439
8440 if ( rot != 0 ) //if rotated
8441 {
8442 switch(mode)
8443 {
8444 case 1:
8445 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8446 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8447
8448 break;
8449
8450 case 2:
8451 //pivot?
8452 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8453 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8454 //Pivoting requires two more args
8455 break;
8456
8457 case 3:
8458 //pivot + trans
8459 //return an error, cannot both rotate and pivot
8460 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8461 break;
8462
8463 case 4:
8464 //flip v
8465 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8466 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8467 break;
8468
8469 case 5:
8470 //trans + v flip
8471 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8472 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8473 break;
8474
8475 case 6:
8476 //pivot + v flip
8477 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8478 //return an error, cannot both rotate and pivot
8479 break;
8480
8481 case 8:
8482 //flip h
8483 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8484 //return an error, cannot both rotate and flip H
8485 break;
8486
8487 case 9:
8488 //trans + h flip
8489 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8490 //return an error, cannot rotate and flip a trans sprite
8491 break;
8492
8493 case 10:
8494 //flip H and pivot
8495 //return error cannot pivot and h flip
8496 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8497 break;
8498
8499 case 12:
8500 //vh flip
8501 //return an error, cannot rotate and VH flip a trans sprite
8502 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8503 break;
8504
8505 case 13:
8506 //trans + vh flip
8507 //return an error, cannot rotate and VH flip a trans sprite
8508 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8509 break;
8510
8511 case 14:
8512 //pivot and vh flip
8513 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8514 //return error cannot both pivot and vh flip
8515 break;
8516
8517 case 16:
8518 //lit
8519 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8520 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8521 break;
8522
8523 case 18:
8524 //pivot, lit
8525 //return an error, cannot both rotate and pivot
8526 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8527 break;
8528
8529 case 20:
8530 //lit + vflip
8531 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8532 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8533 break;
8534
8535 case 22:
8536 //Pivot, vflip, lit
8537 //return an error, cannot both rotate and pivot
8538 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8539 break;
8540
8541 case 24:
8542 //lit + h flip
8543 //return an error, cannot both rotate and H flip
8544 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8545 break;
8546
8547 case 26:
8548 //pivot + lit + hflip
8549 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8550 //return error cannot pivot, lit, and flip
8551 break;
8552
8553 case 28:
8554 //lit + vh flip
8555 //return an error, cannot both rotate and VH flip
8556 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8557 break;
8558
8559 case 32: //gouraud
8560 //Probably not wort supporting.
8561 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8562 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8563 break;
8564
8565 case 0:
8566 //no effect.
8567 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8568 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8569 break;
8570
8571 default:
8572 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8573
8574 }
8575 }
8576
8577 } //end if stretched, but not masked
8578 }
8579 else //not stretched
8580 {
8581
8582
2/2
✓ Branch 0 taken 113326 times.
✓ Branch 1 taken 3 times.
113329 if(masked) //if masked, but not stretched
8583 {
8584
8585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
113326 if ( rot == 0 ) //if not rotated
8586 {
8587
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 113326 times.
113326 switch(mode)
8588 {
8589 case 1:
8590 //transparent
8591 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8592 draw_trans_sprite(newDest, subBmp, dx, dy);
8593 break;
8594
8595
8596 case 2:
8597 //pivot?
8598 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8599 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8600 //Pivoting requires two more args
8601 break;
8602
8603 case 3:
8604 //pivot + trans
8605 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8606 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8607 break;
8608
8609 case 4:
8610 //flip v
8611 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8612 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8613 break;
8614
8615 case 5:
8616 //trans + v flip
8617 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8618 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8619 break;
8620
8621 case 6:
8622 //pivot + v flip
8623 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8624 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8625 break;
8626
8627 case 8:
8628 //vlip h
8629 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8630 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8631 break;
8632
8633 case 9:
8634 //trans + h flip
8635 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8636 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8637 break;
8638
8639 case 10:
8640 //flip H and pivot
8641 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8642 //return error cannot pivot and h flip
8643 break;
8644
8645 case 12:
8646 //vh flip
8647 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8648 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8649 break;
8650
8651 case 13:
8652 //trans + vh flip
8653 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8654 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8655 break;
8656
8657 case 14:
8658 //pivot and vh flip
8659 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8660 //return error cannot both pivot and vh flip
8661 break;
8662
8663 case 16:
8664 //lit
8665 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8666 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8667 break;
8668
8669 case 18:
8670 //pivot, lit
8671 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8672 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8673 break;
8674
8675 case 20:
8676 //lit + v flip
8677 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8678 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8679 break;
8680
8681 case 22:
8682 //Pivot, vflip, lit
8683 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8684 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8685 break;
8686
8687 case 24:
8688 //lit + h flip
8689 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8690 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8691 break;
8692
8693 case 26:
8694 //pivot + lit + hflip
8695 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8696 //return error cannot pivot, lit, and flip
8697 break;
8698
8699 case 28:
8700 //lit + vh flip
8701 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8702 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8703 break;
8704
8705 case 32: //gouraud
8706 //Probably not wort supporting.
8707 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8708 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8709 break;
8710
8711 case 0:
8712 //no effect
8713 113326 masked_blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8714 113326 break;
8715
8716
8717 default:
8718 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8719
8720
8721 }
8722 113326 } //end if not rotated
8723
8724
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( rot != 0 ) //if rotated
8725 {
8726 switch(mode)
8727 {
8728 case 1:
8729 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //transparent
8730 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8731
8732 break;
8733
8734 case 2:
8735 //pivot?
8736 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8737 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8738 //Pivoting requires two more args
8739 break;
8740
8741 case 3:
8742 //pivot + trans
8743 //return an error, cannot both rotate and pivot
8744 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8745 break;
8746
8747 case 4:
8748 //flip v
8749 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8750 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8751 break;
8752
8753 case 5:
8754 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
8755 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8756 break;
8757
8758 case 6:
8759 //pivot + v flip
8760 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8761 //return an error, cannot both rotate and pivot
8762 break;
8763
8764 case 8:
8765 //flip h
8766 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8767 //return an error, cannot both rotate and flip H
8768 break;
8769
8770 case 9:
8771 //trans + h flip
8772 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8773 //return an error, cannot rotate and flip a trans sprite
8774 break;
8775
8776 case 10:
8777 //flip H and pivot
8778 //return error cannot pivot and h flip
8779 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8780 break;
8781
8782 case 12:
8783 //vh flip
8784 //return an error, cannot rotate and VH flip a trans sprite
8785 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8786 break;
8787
8788 case 13:
8789 //trans + vh flip
8790 //return an error, cannot rotate and VH flip a trans sprite
8791 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8792 break;
8793
8794 case 14:
8795 //pivot and vh flip
8796 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8797 //return error cannot both pivot and vh flip
8798 break;
8799
8800 case 16:
8801 //lit
8802 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8803 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8804 break;
8805
8806 case 18:
8807 //pivot, lit
8808 //return an error, cannot both rotate and pivot
8809 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8810 break;
8811
8812 case 20:
8813 //lit + vflip
8814 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8815 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8816 break;
8817
8818 case 22:
8819 //Pivot, vflip, lit
8820 //return an error, cannot both rotate and pivot
8821 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8822 break;
8823
8824 case 24:
8825 //lit + h flip
8826 //return an error, cannot both rotate and H flip
8827 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8828 break;
8829
8830 case 26:
8831 //pivot + lit + hflip
8832 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8833 //return error cannot pivot, lit, and flip
8834 break;
8835
8836 case 28:
8837 //lit + vh flip
8838 //return an error, cannot both rotate and VH flip
8839 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8840 break;
8841
8842 case 32: //gouraud
8843 //Probably not wort supporting.
8844 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8845 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8846 break;
8847
8848 case 0:
8849 //no effect.
8850 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8851 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8852 break;
8853
8854 default:
8855 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8856
8857 }
8858 } //end rtated, masked
8859 113326 } //end if masked
8860
8861 else //not masked, and not stretched; just blit
8862 {
8863
8864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( rot == 0 ) //if not rotated
8865 {
8866
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
3 switch(mode)
8867 {
8868 case 1:
8869 //transparent
8870 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8871 draw_trans_sprite(newDest, subBmp, dx, dy);
8872 break;
8873
8874
8875 case 2:
8876 //pivot?
8877 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8878 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8879 //Pivoting requires two more args
8880 break;
8881
8882 case 3:
8883 //pivot + trans
8884 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8885 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8886 break;
8887
8888 case 4:
8889 //flip v
8890 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8891 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8892 break;
8893
8894 case 5:
8895 //trans + v flip
8896 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8897 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8898 break;
8899
8900 case 6:
8901 //pivot + v flip
8902 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8903 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8904 break;
8905
8906 case 8:
8907 //vlip h
8908 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8909 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8910 break;
8911
8912 case 9:
8913 //trans + h flip
8914 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8915 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8916 break;
8917
8918 case 10:
8919 //flip H and pivot
8920 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8921 //return error cannot pivot and h flip
8922 break;
8923
8924 case 12:
8925 //vh flip
8926 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8927 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8928 break;
8929
8930 case 13:
8931 //trans + vh flip
8932 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8933 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8934 break;
8935
8936 case 14:
8937 //pivot and vh flip
8938 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8939 //return error cannot both pivot and vh flip
8940 break;
8941
8942 case 16:
8943 //lit
8944 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8945 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8946 break;
8947
8948 case 18:
8949 //pivot, lit
8950 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8951 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8952 break;
8953
8954 case 20:
8955 //lit + v flip
8956 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8957 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8958 break;
8959
8960 case 22:
8961 //Pivot, vflip, lit
8962 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8963 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8964 break;
8965
8966 case 24:
8967 //lit + h flip
8968 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8969 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8970 break;
8971
8972 case 26:
8973 //pivot + lit + hflip
8974 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8975 //return error cannot pivot, lit, and flip
8976 break;
8977
8978 case 28:
8979 //lit + vh flip
8980 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8981 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8982 break;
8983
8984 case 32: //gouraud
8985 //Probably not wort supporting.
8986 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8987 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8988 break;
8989
8990 case 0:
8991 //no effect
8992 3 blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8993 3 break;
8994
8995
8996 default:
8997 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8998
8999
9000 }
9001 3 } //end if not rotated
9002
9003
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( rot != 0 ) //if rotated
9004 {
9005 switch(mode)
9006 {
9007 case 1:
9008 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);//transparent
9009 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9010
9011 break;
9012
9013 case 2:
9014 //pivot?
9015 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9016 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9017 //Pivoting requires two more args
9018 break;
9019
9020 case 3:
9021 //pivot + trans
9022 //return an error, cannot both rotate and pivot
9023 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9024 break;
9025
9026 case 4:
9027 //flip v
9028 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9029 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9030 break;
9031
9032 case 5:
9033 //trans + v flip
9034 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9035 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9036 break;
9037
9038 case 6:
9039 //pivot + v flip
9040 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9041 //return an error, cannot both rotate and pivot
9042 break;
9043
9044 case 8:
9045 //flip h
9046 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
9047 //return an error, cannot both rotate and flip H
9048 break;
9049
9050 case 9:
9051 //trans + h flip
9052 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
9053 //return an error, cannot rotate and flip a trans sprite
9054 break;
9055
9056 case 10:
9057 //flip H and pivot
9058 //return error cannot pivot and h flip
9059 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
9060 break;
9061
9062 case 12:
9063 //vh flip
9064 //return an error, cannot rotate and VH flip a trans sprite
9065 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9066 break;
9067
9068 case 13:
9069 //trans + vh flip
9070 //return an error, cannot rotate and VH flip a trans sprite
9071 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9072 break;
9073
9074 case 14:
9075 //pivot and vh flip
9076 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9077 //return error cannot both pivot and vh flip
9078 break;
9079
9080 case 16:
9081 //lit
9082 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9083 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9084 break;
9085
9086 case 18:
9087 //pivot, lit
9088 //return an error, cannot both rotate and pivot
9089 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9090 break;
9091
9092 case 20:
9093 //lit + vflip
9094 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9095 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9096 break;
9097
9098 case 22:
9099 //Pivot, vflip, lit
9100 //return an error, cannot both rotate and pivot
9101 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9102 break;
9103
9104 case 24:
9105 //lit + h flip
9106 //return an error, cannot both rotate and H flip
9107 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
9108 break;
9109
9110 case 26:
9111 //pivot + lit + hflip
9112 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
9113 //return error cannot pivot, lit, and flip
9114 break;
9115
9116 case 28:
9117 //lit + vh flip
9118 //return an error, cannot both rotate and VH flip
9119 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9120 break;
9121
9122 case 32: //gouraud
9123 //Probably not wort supporting.
9124 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9125 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9126 break;
9127
9128 case 0:
9129 //no effect.
9130 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9131 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9132 break;
9133
9134 default:
9135 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9136
9137 }
9138 } //end if rotated
9139 } //end if not masked
9140 } //end if not stretched
9141
9142 //cleanup
9143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(subBmp)
9144 {
9145 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
9146 destroy_bitmap(subBmp);
9147 }
9148
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113326 times.
113329 if(newSource != destBMP)
9149 {
9150 3 destroy_bitmap(newSource);
9151 3 }
9152 113329 }
9153
9154
9155 void bmp_do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
9156 {
9157
9158 //sdci[1]=layer
9159 //sdci[2]=pos[12]
9160 //sdci[3]=uv[8]
9161 //sdci[4]=color[4]
9162 //sdci[5]=size[2]
9163 //sdci[6]=flip
9164 //sdci[7]=tile/combo
9165 //sdci[8]=polytype
9166 //sdci[9] = other bitmap as texture
9167 //sdci[17] Bitmap Pointer
9168 if ( sdci[17] <= 0 )
9169 {
9170 Z_scripterrlog("bitmap->Quad3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
9171 return;
9172 }
9173 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
9174 if ( refbmp == NULL ) return;
9175
9176 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
9177
9178 if(!v_ptr)
9179 {
9180 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
9181 return;
9182 }
9183
9184 std::vector<int32_t> &v = *v_ptr;
9185
9186 if(v.empty())
9187 return;
9188
9189 int32_t* pos = &v[0];
9190 int32_t* uv = &v[12];
9191 int32_t* col = &v[20];
9192 int32_t* size = &v[24];
9193
9194 int32_t w = size[0]; //magic numerical constants... yuck.
9195 int32_t h = size[1];
9196 int32_t flip = (sdci[6]/10000)&3;
9197 int32_t tile = sdci[7]/10000;
9198 int32_t polytype = sdci[8]/10000;
9199 int32_t quad_render_source = sdci[9];
9200 Z_scripterrlog("Quad3D texture is %d\n", quad_render_source);
9201
9202 polytype = vbound(polytype, 0, 14);
9203
9204 int32_t tex_width = w*16;
9205 int32_t tex_height = h*16;
9206
9207 bool mustDestroyBmp = false;
9208 BITMAP *tex=NULL;
9209
9210
9211 bool tex_is_bitmap = ( sdci[9] != 0 );
9212 //Z_scripterrlog("sdci[9] is %d\n", quad_render_source);
9213 //Z_scripterrlog("sdci[17] is %d\n", sdci[17]);
9214 BITMAP *bmptexture;
9215
9216 if ( tex_is_bitmap ) bmptexture = FFCore.GetScriptBitmap(quad_render_source);
9217
9218 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9219
9220
9221 if ( !tex_is_bitmap )
9222 {
9223 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
9224
9225 if(!tex)
9226 {
9227 mustDestroyBmp = true;
9228 tex = create_bitmap_ex(8, tex_width, tex_height);
9229 clear_bitmap(tex);
9230 }
9231 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
9232 {
9233 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
9234 return; //non power of two error
9235 }
9236 if(tile > 0) // TILE
9237 {
9238 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
9239 }
9240 else // COMBO
9241 {
9242 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
9243 const int32_t tiletodraw = combo_tile(c, 0, 0);
9244 flip = flip ^ c.flip;
9245
9246 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
9247 }
9248
9249 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9250 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9251 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9252 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
9253
9254 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
9255 if(mustDestroyBmp)
9256 destroy_bitmap(tex);
9257 }
9258 else
9259 {
9260
9261 if ( !bmptexture )
9262 {
9263 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Quad3D()");
9264 tex_is_bitmap = 0;
9265 return;
9266 }
9267 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9268 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9269 if ( !isPowerOfTwo(h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
9270 if ( !isPowerOfTwo(w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
9271
9272 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9273 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9274 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9275 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
9276
9277 BITMAP *foo = create_bitmap_ex(8, 256, 176);
9278
9279 //quad3d_f(refbmp, polytype, foo, &V1, &V2, &V3, &V4);
9280 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
9281 destroy_bitmap(foo);
9282
9283 }
9284
9285
9286
9287 }
9288
9289
9290
9291 void bmp_do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
9292 {
9293 //sdci[1]=layer
9294 //sdci[2]=pos[9]
9295 //sdci[3]=uv[6]
9296 //sdci[4]=color[3]
9297 //sdci[5]=size[2]
9298 //sdci[6]=flip
9299 //sdci[7]=tile/combo
9300 //sdci[8]=polytype
9301 //sdci[9] bitmap as texture
9302 //sdci[17] Bitmap Pointer
9303 if ( sdci[17] <= 0 )
9304 {
9305 Z_scripterrlog("bitmap->Triangle3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[17]);
9306 return;
9307 }
9308 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
9309 if ( refbmp == NULL ) return;
9310
9311 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
9312
9313 if(!v_ptr)
9314 {
9315 al_trace("bitmap->Triangle3d: Vector pointer is null! Internal error. \n");
9316 return;
9317 }
9318
9319 std::vector<int32_t> &v = *v_ptr;
9320
9321 if(v.empty())
9322 return;
9323
9324 int32_t* pos = &v[0];
9325 int32_t* uv = &v[9];
9326 int32_t* col = &v[15];
9327 int32_t* size = &v[18];
9328
9329 int32_t w = size[0]; //magic numerical constants... yuck.
9330 int32_t h = size[1];
9331 int32_t flip = (sdci[6]/10000)&3;
9332 int32_t tile = sdci[7]/10000;
9333 int32_t polytype = sdci[8]/10000;
9334 int32_t quad_render_source = sdci[9];
9335 polytype = vbound(polytype, 0, 14);
9336
9337 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
9338 {
9339 Z_message("bitmap->Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
9340 return; //non power of two error
9341 }
9342
9343 int32_t tex_width = w*16;
9344 int32_t tex_height = h*16;
9345
9346 bool mustDestroyBmp = false;
9347 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
9348
9349 if(!tex)
9350 {
9351 mustDestroyBmp = true;
9352 tex = create_bitmap_ex(8, tex_width, tex_height);
9353 clear_bitmap(tex);
9354 }
9355
9356 bool tex_is_bitmap = ( sdci[9] != 0 );
9357 BITMAP *bmptexture=NULL;
9358 if ( tex_is_bitmap )
9359 {
9360 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
9361 if ( !bmptexture )
9362 {
9363 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
9364 tex_is_bitmap = 0;
9365 }
9366 }
9367
9368 if ( !tex_is_bitmap )
9369 {
9370 if(tile > 0) // TILE
9371 {
9372 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
9373 }
9374 else // COMBO
9375 {
9376 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
9377 const int32_t tiletodraw = combo_tile(c, 0, 0);
9378 flip = flip ^ c.flip;
9379
9380 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
9381 }
9382
9383 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9384 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9385 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9386
9387 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
9388 }
9389 else
9390 {
9391 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9392 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
9393 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
9394 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
9395
9396 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
9397 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
9398 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
9399
9400 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
9401
9402
9403 }
9404 if(mustDestroyBmp)
9405 destroy_bitmap(tex);
9406
9407 }
9408
9409
9410 bool is_layer_transparent(const mapscr& m, int32_t layer)
9411 {
9412 layer = vbound(layer, 0, 5);
9413 return m.layeropacity[layer] == 128;
9414 }
9415
9416 4336942 mapscr *getmapscreen(int32_t map_index, int32_t screen_index, int32_t layer) //returns NULL for invalid or non-existent layer
9417 {
9418 mapscr *base_screen;
9419 4336942 int32_t index = map_index*MAPSCRS+screen_index;
9420
9421
2/4
✓ Branch 0 taken 4336942 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4336942 times.
4336942 if((uint32_t)layer > 6 || (uint32_t)index >= TheMaps.size())
9422 return NULL;
9423
9424
2/2
✓ Branch 0 taken 3552036 times.
✓ Branch 1 taken 784906 times.
4336942 if(layer != 0)
9425 {
9426 784906 layer = layer - 1;
9427
9428 784906 base_screen=&(TheMaps[index]);
9429
9430
2/2
✓ Branch 0 taken 748179 times.
✓ Branch 1 taken 36727 times.
784906 if(base_screen->layermap[layer]==0)
9431 36727 return NULL;
9432
9433 748179 index=(base_screen->layermap[layer]-1)*MAPSCRS+base_screen->layerscreen[layer];
9434
9435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748179 times.
748179 if((uint32_t)index >= TheMaps.size()) // Might as well make sure
9436 return NULL;
9437 748179 }
9438
9439 4300215 return &(TheMaps[index]);
9440 4336942 }
9441
9442 191560 void draw_mapscr(BITMAP *b, const mapscr& m, int32_t x, int32_t y, bool transparent)
9443 {
9444
2/2
✓ Branch 0 taken 33714560 times.
✓ Branch 1 taken 191560 times.
33906120 for(int32_t i(0); i < 176; ++i)
9445 {
9446 33714560 const int32_t x2 = ((i&15)<<4) + x;
9447 33714560 const int32_t y2 = (i&0xF0) + y;
9448
9449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33714560 times.
33714560 if(transparent)
9450 {
9451 overcomboblocktranslucent(b, x2, y2, m.data[i], m.cset[i], 1, 1, 128);
9452 }
9453 else
9454 {
9455 33714560 overcomboblock(b, x2, y2, m.data[i], m.cset[i], 1, 1);
9456 }
9457 33714560 }
9458 191560 }
9459
9460 void draw_map_solidity(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9461 {
9462 BITMAP* square = create_bitmap_ex(8,16,16);
9463
9464 for(int32_t i(0); i < 176; ++i)
9465 {
9466 const int32_t x2 = ((i&15)<<4) + x;
9467 const int32_t y2 = (i&0xF0) + y;
9468 //Blit the palette index of the solidity value.
9469 clear_to_color(square,(combobuf[m.data[i]].walk&15));
9470 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9471 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9472 }
9473 destroy_bitmap(square);
9474 }
9475
9476 void do_bmpdrawscreen_solidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9477 {
9478 //sdci[1]=layer
9479 //sdci[2]=map
9480 //sdci[3]=screen
9481 //sdci[4]=x
9482 //sdci[5]=y
9483 //sdci[6]=rotation
9484 //sdci[17] Bitmap Pointer
9485
9486 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
9487 if ( refbmp == NULL ) return;
9488
9489 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9490
9491 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9492 int32_t scrn = sdci[3]/10000;
9493 int32_t x = sdci[4]/10000;
9494 int32_t y = sdci[5]/10000;
9495 int32_t x1 = x + xoffset;
9496 int32_t y1 = y + yoffset;
9497 int32_t rotation = sdci[6]/10000;
9498
9499 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9500
9501 if(index >= TheMaps.size())
9502 {
9503 al_trace("DrawScreen: invalid map or screen index. \n");
9504 return;
9505 }
9506
9507 const mapscr & m = TheMaps[index];
9508
9509
9510 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]);
9511 if ( refbmp == NULL ) return;
9512
9513 if(rotation != 0)
9514 b = script_drawing_commands.AquireSubBitmap(256, 176);
9515
9516 //draw layer 0
9517 draw_map_solidity(b, m, x1, y1);
9518 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
9519 {
9520 for(int32_t i(0); i < 6; ++i)
9521 {
9522 if(m.layermap[i] == 0) continue;
9523
9524 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9525
9526 if(layer_screen_index >= TheMaps.size())
9527 continue;
9528
9529 //draw valid layers
9530 draw_map_solidity(b, TheMaps[ layer_screen_index ], x1, y1);
9531 }
9532 }
9533
9534 if(rotation != 0) // rotate
9535 {
9536 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9537 script_drawing_commands.ReleaseSubBitmap(b);
9538 }
9539 }
9540
9541 void draw_map_solid(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9542 {
9543 BITMAP* square = create_bitmap_ex(8,16,16);
9544 BITMAP* subsquare = create_bitmap_ex(8,16,16);
9545 clear_to_color(subsquare,1);
9546
9547 for(int32_t i(0); i < 176; ++i)
9548 {
9549 const int32_t x2 = ((i&15)<<4) + x;
9550 const int32_t y2 = (i&0xF0) + y;
9551 //Blit the palette index of the solidity value.
9552 //int32_t col = (combobuf[m.data[i]].walk&15);
9553 //if ( col != 0 )
9554 //{
9555 // Z_scripterrlog("Position %d has a solidity value of %d.\n", i, col);
9556 //
9557 //}
9558 clear_bitmap(square);
9559 int32_t sol = (combobuf[m.data[i]].walk);
9560 //al_trace("Solidity is: %d.\n", sol);
9561 if ( sol & 1 )
9562 {
9563 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
9564 }
9565 if ( sol & 2 )
9566 {
9567 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
9568 }
9569 if ( sol & 4 )
9570 {
9571 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
9572 }
9573 if ( sol &8 ) {
9574 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
9575 }
9576
9577 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9578 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9579 }
9580 destroy_bitmap(square);
9581 destroy_bitmap(subsquare);
9582 }
9583
9584 void do_bmpdrawscreen_solidr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9585 {
9586 //sdci[1]=layer
9587 //sdci[2]=map
9588 //sdci[3]=screen
9589 //sdci[4]=x
9590 //sdci[5]=y
9591 //sdci[6]=rotation
9592 //sdci[17] Bitmap Pointer
9593
9594 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
9595 if ( refbmp == NULL ) return;
9596
9597 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9598
9599 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9600 int32_t scrn = sdci[3]/10000;
9601 int32_t x = sdci[4]/10000;
9602 int32_t y = sdci[5]/10000;
9603 int32_t x1 = x + xoffset;
9604 int32_t y1 = y + yoffset;
9605 int32_t rotation = sdci[6]/10000;
9606
9607 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9608
9609 if(index >= TheMaps.size())
9610 {
9611 al_trace("DrawScreen: invalid map or screen index. \n");
9612 return;
9613 }
9614
9615 const mapscr & m = TheMaps[index];
9616
9617
9618 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]);
9619 if ( refbmp == NULL ) return;
9620
9621 if(rotation != 0)
9622 b = script_drawing_commands.AquireSubBitmap(256, 176);
9623
9624 //draw layer 0
9625 draw_map_solid(b, m, x1, y1);
9626
9627 for(int32_t i(0); i < 6; ++i) //This one doesn't need the QR; it works just fine.
9628 {
9629 if(m.layermap[i] == 0) continue;
9630
9631 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9632
9633 if(layer_screen_index >= TheMaps.size())
9634 continue;
9635
9636 //draw valid layers
9637 draw_map_solid(b, TheMaps[ layer_screen_index ], x1, y1);
9638 }
9639
9640 if(rotation != 0) // rotate
9641 {
9642 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9643 script_drawing_commands.ReleaseSubBitmap(b);
9644 }
9645 }
9646
9647 1024 void draw_map_cflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9648 {
9649 1024 BITMAP* square = create_bitmap_ex(8,16,16);
9650
9651
2/2
✓ Branch 0 taken 180224 times.
✓ Branch 1 taken 1024 times.
181248 for(int32_t i(0); i < 176; ++i)
9652 {
9653 180224 const int32_t x2 = ((i&15)<<4) + x;
9654 180224 const int32_t y2 = (i&0xF0) + y;
9655 //Blit the palette index of the solidity value.
9656 180224 clear_to_color(square,m.sflag[i]);
9657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180224 times.
180224 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9658 180224 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9659 180224 }
9660 1024 destroy_bitmap(square);
9661 1024 }
9662
9663 1024 void do_bmpdrawscreen_cflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9664 {
9665 //sdci[1]=layer
9666 //sdci[2]=map
9667 //sdci[3]=screen
9668 //sdci[4]=x
9669 //sdci[5]=y
9670 //sdci[6]=rotation
9671 //sdci[17] Bitmap Pointer
9672
9673 1024 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
9674
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
9675
9676
2/4
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1024 times.
✗ Branch 3 not taken.
1024 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9677
9678 1024 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9679 1024 int32_t scrn = sdci[3]/10000;
9680 1024 int32_t x = sdci[4]/10000;
9681 1024 int32_t y = sdci[5]/10000;
9682 1024 int32_t x1 = x + xoffset;
9683 1024 int32_t y1 = y + yoffset;
9684 1024 int32_t rotation = sdci[6]/10000;
9685
9686 1024 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9687
9688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024 times.
1024 if(index >= TheMaps.size())
9689 {
9690 al_trace("DrawScreen: invalid map or screen index. \n");
9691 return;
9692 }
9693
9694 1024 const mapscr & m = TheMaps[index];
9695
9696
9697 1024 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]);
9698
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
9699
9700
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0)
9701 b = script_drawing_commands.AquireSubBitmap(256, 176);
9702
9703 //draw layer 0
9704 1024 draw_map_cflag(b, m, x1, y1);
9705
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
9706 {
9707 for(int32_t i(0); i < 6; ++i)
9708 {
9709 if(m.layermap[i] == 0) continue;
9710
9711 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9712
9713 if(layer_screen_index >= TheMaps.size())
9714 continue;
9715
9716 //draw valid layers
9717 draw_map_cflag(b, TheMaps[ layer_screen_index ], x1, y1);
9718 }
9719 }
9720
9721
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0) // rotate
9722 {
9723 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9724 script_drawing_commands.ReleaseSubBitmap(b);
9725 }
9726 1024 }
9727
9728
9729 void draw_map_combotype(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9730 {
9731 BITMAP* square = create_bitmap_ex(8,16,16);
9732
9733 for(int32_t i(0); i < 176; ++i)
9734 {
9735 const int32_t x2 = ((i&15)<<4) + x;
9736 const int32_t y2 = (i&0xF0) + y;
9737 //Blit the palette index of the solidity value.
9738 clear_to_color(square,(combobuf[m.data[i]].type));
9739 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9740 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9741 }
9742 destroy_bitmap(square);
9743 }
9744
9745 void do_bmpdrawscreen_ctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9746 {
9747 //sdci[1]=layer
9748 //sdci[2]=map
9749 //sdci[3]=screen
9750 //sdci[4]=x
9751 //sdci[5]=y
9752 //sdci[6]=rotation
9753 //sdci[17] Bitmap Pointer
9754
9755 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
9756 if ( refbmp == NULL ) return;
9757
9758 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9759
9760 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9761 int32_t scrn = sdci[3]/10000;
9762 int32_t x = sdci[4]/10000;
9763 int32_t y = sdci[5]/10000;
9764 int32_t x1 = x + xoffset;
9765 int32_t y1 = y + yoffset;
9766 int32_t rotation = sdci[6]/10000;
9767
9768 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9769
9770 if(index >= TheMaps.size())
9771 {
9772 al_trace("DrawScreen: invalid map or screen index. \n");
9773 return;
9774 }
9775
9776 const mapscr & m = TheMaps[index];
9777
9778
9779 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]);
9780 if ( refbmp == NULL ) return;
9781
9782 if(rotation != 0)
9783 b = script_drawing_commands.AquireSubBitmap(256, 176);
9784
9785 //draw layer 0
9786 draw_map_combotype(b, m, x1, y1);
9787
9788 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
9789 {
9790 for(int32_t i(0); i < 6; ++i)
9791 {
9792 if(m.layermap[i] == 0) continue;
9793
9794 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9795
9796 if(layer_screen_index >= TheMaps.size())
9797 continue;
9798
9799 //draw valid layers
9800 draw_map_combotype(b, TheMaps[ layer_screen_index ], x1, y1);
9801 }
9802 }
9803
9804 if(rotation != 0) // rotate
9805 {
9806 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9807 script_drawing_commands.ReleaseSubBitmap(b);
9808 }
9809 }
9810
9811
9812 void draw_map_comboiflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
9813 {
9814 BITMAP* square = create_bitmap_ex(8,16,16);
9815
9816 for(int32_t i(0); i < 176; ++i)
9817 {
9818 const int32_t x2 = ((i&15)<<4) + x;
9819 const int32_t y2 = (i&0xF0) + y;
9820 //Blit the palette index of the solidity value.
9821 clear_to_color(square,(combobuf[m.data[i]].flag));
9822 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
9823 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
9824 }
9825 destroy_bitmap(square);
9826 }
9827
9828 void do_bmpdrawscreen_ciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9829 {
9830 //sdci[1]=layer
9831 //sdci[2]=map
9832 //sdci[3]=screen
9833 //sdci[4]=x
9834 //sdci[5]=y
9835 //sdci[6]=rotation
9836 //sdci[17] Bitmap Pointer
9837
9838 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
9839 if ( refbmp == NULL ) return;
9840
9841 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
9842
9843 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9844 int32_t scrn = sdci[3]/10000;
9845 int32_t x = sdci[4]/10000;
9846 int32_t y = sdci[5]/10000;
9847 int32_t x1 = x + xoffset;
9848 int32_t y1 = y + yoffset;
9849 int32_t rotation = sdci[6]/10000;
9850
9851 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9852
9853 if(index >= TheMaps.size())
9854 {
9855 al_trace("DrawScreen: invalid map or screen index. \n");
9856 return;
9857 }
9858
9859 const mapscr & m = TheMaps[index];
9860
9861
9862 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]);
9863 if ( refbmp == NULL ) return;
9864
9865 if(rotation != 0)
9866 b = script_drawing_commands.AquireSubBitmap(256, 176);
9867
9868 //draw layer 0
9869 draw_map_comboiflag(b, m, x1, y1);
9870
9871 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
9872 {
9873 for(int32_t i(0); i < 6; ++i)
9874 {
9875 if(m.layermap[i] == 0) continue;
9876
9877 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
9878
9879 if(layer_screen_index >= TheMaps.size())
9880 continue;
9881
9882 //draw valid layers
9883 draw_map_comboiflag(b, TheMaps[ layer_screen_index ], x1, y1);
9884 }
9885 }
9886
9887 if(rotation != 0) // rotate
9888 {
9889 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
9890 script_drawing_commands.ReleaseSubBitmap(b);
9891 }
9892 }
9893
9894 4335769 void do_drawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9895 {
9896 //sdci[1]=layer
9897 //sdci[2]=map
9898 //sdci[3]=screen
9899 //sdci[4]=layer
9900 //sdci[5]=x
9901 //sdci[6]=y
9902 //sdci[7]=rotation
9903 //sdci[8]=opacity
9904
9905 4335769 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9906 4335769 int32_t scrn = sdci[3]/10000;
9907 4335769 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
9908 4335769 int32_t x = sdci[5]/10000;
9909 4335769 int32_t y = sdci[6]/10000;
9910 4335769 int32_t x1 = x + xoffset;
9911 4335769 int32_t y1 = y + yoffset;
9912 4335769 int32_t rotation = sdci[7]/10000;
9913 4335769 int32_t opacity = sdci[8]/10000;
9914
9915 4335769 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9916 4335769 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
9917
9918
2/2
✓ Branch 0 taken 4299048 times.
✓ Branch 1 taken 36721 times.
4335769 if(!m) //no need to log it.
9919 36721 return;
9920
9921
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4299048 times.
4299048 if(index >= TheMaps.size())
9922 {
9923 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
9924 return;
9925 }
9926
9927 4299048 const mapscr & l = *m;
9928
9929 4299048 BITMAP* b = bmp;
9930
9931
1/2
✓ Branch 0 taken 4299048 times.
✗ Branch 1 not taken.
4299048 if(rotation != 0)
9932 b = script_drawing_commands.AquireSubBitmap(256, 176);
9933
9934
9935 4299048 const int32_t maxX = isOffScreen ? 512 : 256;
9936
2/2
✓ Branch 0 taken 4280939 times.
✓ Branch 1 taken 18109 times.
4299048 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
9937 4299048 bool transparent = opacity <= 128;
9938
9939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4299048 times.
4299048 if(rotation != 0) // rotate
9940 {
9941 draw_mapscr(b, l, x1, y1, transparent);
9942
9943 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
9944 script_drawing_commands.ReleaseSubBitmap(b);
9945 }
9946 else
9947 {
9948
2/2
✓ Branch 0 taken 756632448 times.
✓ Branch 1 taken 4299048 times.
760931496 for(int32_t i(0); i < 176; ++i)
9949 {
9950 756632448 const int32_t x2 = ((i&15)<<4) + x1;
9951 756632448 const int32_t y2 = (i&0xF0) + y1;
9952
9953
7/8
✓ Branch 0 taken 666127814 times.
✓ Branch 1 taken 90504634 times.
✓ Branch 2 taken 666127814 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 611722422 times.
✓ Branch 5 taken 54405392 times.
✓ Branch 6 taken 9155742 times.
✓ Branch 7 taken 602566680 times.
756632448 if(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY) //in clipping rect
9954 {
9955 602566680 const newcombo & c = combobuf[ l.data[i] ];
9956 602566680 const int32_t tile = combo_tile(c, x2, y2);
9957
9958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 602566680 times.
602566680 if(opacity < 128)
9959 {
9960 overcomboblocktranslucent(b, x2, y2, l.data[i], l.cset[i], 1, 1, 128);
9961
9962
9963 //overtiletranslucent16(b, tile, x2, y2, l.cset[i], c.flip, opacity);
9964 }
9965 else
9966 {
9967 602566680 overcomboblock(b, x2, y2, l.data[i], l.cset[i], 1, 1);
9968 //overtile16(b, tile, x2, y2, l.cset[i], c.flip);
9969 }
9970 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
9971 602566680 }
9972 756632448 }
9973 }
9974
9975 //putscr
9976 4335769 }
9977
9978
9979
9980 50406 void do_drawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
9981 {
9982 //sdci[1]=layer
9983 //sdci[2]=map
9984 //sdci[3]=screen
9985 //sdci[4]=x
9986 //sdci[5]=y
9987 //sdci[6]=rotation
9988
9989 50406 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
9990 50406 int32_t scrn = sdci[3]/10000;
9991 50406 int32_t x = sdci[4]/10000;
9992 50406 int32_t y = sdci[5]/10000;
9993 50406 int32_t x1 = x + xoffset;
9994 50406 int32_t y1 = y + yoffset;
9995 50406 int32_t rotation = sdci[6]/10000;
9996
9997 50406 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
9998
9999
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(index >= TheMaps.size())
10000 {
10001 al_trace("DrawScreen: invalid map or screen index. \n");
10002 return;
10003 }
10004
10005 50406 const mapscr & m = TheMaps[index];
10006
10007
10008 50406 BITMAP* b = bmp;
10009
10010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0)
10011 b = script_drawing_commands.AquireSubBitmap(256, 176);
10012
10013 //draw layer 0
10014 50406 draw_mapscr(b, m, x1, y1, false);
10015
10016
2/2
✓ Branch 0 taken 50406 times.
✓ Branch 1 taken 302436 times.
352842 for(int32_t i(0); i < 6; ++i)
10017 {
10018
2/2
✓ Branch 0 taken 137944 times.
✓ Branch 1 taken 164492 times.
302436 if(m.layermap[i] == 0) continue;
10019
10020 137944 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10021
10022
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137944 times.
137944 if(layer_screen_index >= TheMaps.size())
10023 continue;
10024
10025 137944 bool trans = m.layeropacity[i] == 128;
10026
10027 //draw valid layers
10028 137944 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
10029 137944 }
10030
10031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0) // rotate
10032 {
10033 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10034 script_drawing_commands.ReleaseSubBitmap(b);
10035 }
10036 50406 }
10037
10038
10039 1173 void do_bmpdrawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10040 {
10041 //sdci[1]=layer
10042 //sdci[2]=map
10043 //sdci[3]=screen
10044 //sdci[4]=layer
10045 //sdci[5]=x
10046 //sdci[6]=y
10047 //sdci[7]=rotation
10048 //[8] noclip
10049 //sdci[9]=opacity
10050 //sdci[17] Bitmap Pointer
10051
10052 1173 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
10053
1/2
✓ Branch 0 taken 1173 times.
✗ Branch 1 not taken.
1173 if ( refbmp == NULL ) return;
10054
10055 1173 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10056 1173 int32_t scrn = sdci[3]/10000;
10057 1173 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10058 1173 int32_t x = sdci[5]/10000;
10059 1173 int32_t y = sdci[6]/10000;
10060 1173 int32_t rotation = sdci[7]/10000;
10061
10062 1173 byte noclip = 0;//(sdci[8]!=0);
10063 1173 int32_t opacity = sdci[8]/10000;
10064 //zprint2("Running bmp->DrawLayer(%d, %d, %d, %d, %d, %d, %d, %d)\n", sdci[1]/10000, map, scrn, sourceLayer, x, y, rotation, opacity);
10065 1173 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10066 1173 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10067
10068
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 6 times.
1173 if(!m) //no need to log it.
10069 6 return;
10070
10071
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(index >= TheMaps.size())
10072 {
10073 Z_scripterrlog("DrawLayer: invalid map index \"%i\". Map count is %d.\n", index, TheMaps.size());
10074 return;
10075 }
10076
10077 1167 const mapscr & l = *m;
10078
10079 1167 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]);
10080
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if ( refbmp == NULL ) return;
10081
2/4
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1167 times.
✗ Branch 3 not taken.
1167 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
10082
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if(rotation != 0)
10083 b = script_drawing_commands.AquireSubBitmap(256, 176);
10084
10085
10086 1167 const int32_t maxX = isOffScreen ? 512 : 256;
10087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10088 1167 bool transparent = opacity <= 128;
10089
10090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(rotation != 0) // rotate
10091 {
10092 draw_mapscr(b, l, x, y, transparent);
10093
10094 rotate_sprite(refbmp, b, x, y, degrees_to_fixed(rotation));
10095 script_drawing_commands.ReleaseSubBitmap(b);
10096 }
10097 else
10098 {
10099
2/2
✓ Branch 0 taken 205392 times.
✓ Branch 1 taken 1167 times.
206559 for(int32_t i(0); i < 176; ++i)
10100 {
10101 205392 const int32_t x2 = ((i&15)<<4) + x;
10102 205392 const int32_t y2 = (i&0xF0) + y;
10103
10104 //if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10105 {
10106 205392 const newcombo & c = combobuf[ l.data[i] ];
10107 205392 const int32_t tile = combo_tile(c, x2, y2);
10108
10109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205392 times.
205392 if(opacity < 128)
10110 overtiletranslucent16(refbmp, tile, x2, y2, l.cset[i], c.flip, opacity);
10111 else
10112 205392 overtile16(refbmp, tile, x2, y2, l.cset[i], c.flip);
10113
10114 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
10115 }
10116 205392 }
10117 }
10118
10119 //putscr
10120 1173 }
10121
10122
10123
10124 1092 void do_bmpdrawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10125 {
10126 //sdci[1]=layer
10127 //sdci[2]=map
10128 //sdci[3]=screen
10129 //sdci[4]=x
10130 //sdci[5]=y
10131 //sdci[6]=rotation
10132 //sdci[17] Bitmap Pointer
10133
10134 1092 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[17]);
10135
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if ( refbmp == NULL ) return;
10136
10137
2/4
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1092 times.
1092 if ( (sdci[17]-10) != -2 && (sdci[17]-10) != -1 ) yoffset = 0; //Don't crop.
10138
10139 1092 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10140 1092 int32_t scrn = sdci[3]/10000;
10141 1092 int32_t x = sdci[4]/10000;
10142 1092 int32_t y = sdci[5]/10000;
10143 1092 int32_t x1 = x + xoffset;
10144 1092 int32_t y1 = y + yoffset;
10145 1092 int32_t rotation = sdci[6]/10000;
10146
10147 1092 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10148
10149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if(index >= TheMaps.size())
10150 {
10151 al_trace("DrawScreen: invalid map or screen index. \n");
10152 return;
10153 }
10154
10155 1092 const mapscr & m = TheMaps[index];
10156
10157
10158 1092 BITMAP* b = FFCore.GetScriptBitmap(sdci[17]);
10159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if ( refbmp == NULL ) return;
10160
10161
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0)
10162 b = script_drawing_commands.AquireSubBitmap(256, 176);
10163
10164 //draw layer 0
10165 1092 draw_mapscr(b, m, x1, y1, false);
10166
10167
2/2
✓ Branch 0 taken 1092 times.
✓ Branch 1 taken 6552 times.
7644 for(int32_t i(0); i < 6; ++i)
10168 {
10169
2/2
✓ Branch 0 taken 2118 times.
✓ Branch 1 taken 4434 times.
6552 if(m.layermap[i] == 0) continue;
10170
10171 2118 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10172
10173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2118 times.
2118 if(layer_screen_index >= TheMaps.size())
10174 continue;
10175
10176 2118 bool trans = m.layeropacity[i] == 128;
10177
10178 //draw valid layers
10179 2118 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
10180 2118 }
10181
10182
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0) // rotate
10183 {
10184 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10185 script_drawing_commands.ReleaseSubBitmap(b);
10186 }
10187 1092 }
10188
10189 void do_bmpdrawlayersolidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10190 {
10191 //sdci[1]=layer
10192 //sdci[2]=map
10193 //sdci[3]=screen
10194 //sdci[4]=layer
10195 //sdci[5]=x
10196 //sdci[6]=y
10197 //sdci[7]=rotation
10198 //sdci[8]=bool noclip
10199 //sdci[9] == opacity
10200
10201 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10202 int32_t scrn = sdci[3]/10000;
10203 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10204 int32_t x = sdci[5]/10000;
10205 int32_t y = sdci[6]/10000;
10206 int32_t x1 = x + xoffset;
10207 int32_t y1 = y + yoffset;
10208 int32_t rotation = sdci[7]/10000;
10209 byte noclip = (sdci[8]!=0);
10210 int32_t opacity = sdci[9]/10000;
10211
10212 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10213 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10214
10215 if(!m) //no need to log it.
10216 return;
10217
10218 if(index >= TheMaps.size())
10219 {
10220 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10221 return;
10222 }
10223
10224 const mapscr & l = *m;
10225
10226 BITMAP* b = bmp;
10227
10228 if(rotation != 0)
10229 b = script_drawing_commands.AquireSubBitmap(256, 176);
10230
10231
10232 const int32_t maxX = isOffScreen ? 512 : 256;
10233 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10234 bool transparent = opacity <= 128;
10235
10236 if(rotation != 0) // rotate
10237 {
10238 draw_map_solid(b, l, x1, y1);
10239
10240 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10241 script_drawing_commands.ReleaseSubBitmap(b);
10242 }
10243 else
10244 {
10245 BITMAP* square = create_bitmap_ex(8,16,16);
10246 BITMAP* subsquare = create_bitmap_ex(8,16,16);
10247 clear_to_color(subsquare,1);
10248 for(int32_t i(0); i < 176; ++i)
10249 {
10250 const int32_t x2 = ((i&15)<<4) + x1;
10251 const int32_t y2 = (i&0xF0) + y1;
10252
10253 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10254 {
10255 int32_t sol = (combobuf[l.data[i]].walk);
10256
10257 if ( sol & 1 )
10258 {
10259 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
10260 }
10261 if ( sol & 2 )
10262 {
10263 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
10264 }
10265 if ( sol & 4 )
10266 {
10267 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
10268 }
10269 if ( sol &8 ) {
10270 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
10271 }
10272
10273 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10274 }
10275 }
10276 destroy_bitmap(square);
10277 destroy_bitmap(subsquare);
10278 }
10279
10280 //putscr
10281 }
10282
10283 void do_bmpdrawlayersolidityr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10284 {
10285 //sdci[1]=layer
10286 //sdci[2]=map
10287 //sdci[3]=screen
10288 //sdci[4]=layer
10289 //sdci[5]=x
10290 //sdci[6]=y
10291 //sdci[7]=rotation
10292 //[8] noclip
10293 //sdci[9]=opacity
10294
10295
10296 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10297 int32_t scrn = sdci[3]/10000;
10298 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10299 int32_t x = sdci[5]/10000;
10300 int32_t y = sdci[6]/10000;
10301 int32_t x1 = x + xoffset;
10302 int32_t y1 = y + yoffset;
10303 int32_t rotation = sdci[7]/10000;
10304 byte noclip = (sdci[8]!=0);
10305 int32_t opacity = sdci[9]/10000;
10306
10307 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10308 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10309
10310 if(!m) //no need to log it.
10311 return;
10312
10313 if(index >= TheMaps.size())
10314 {
10315 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10316 return;
10317 }
10318
10319 const mapscr & l = *m;
10320
10321 BITMAP* b = bmp;
10322
10323 if(rotation != 0)
10324 b = script_drawing_commands.AquireSubBitmap(256, 176);
10325
10326
10327 const int32_t maxX = isOffScreen ? 512 : 256;
10328 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10329 bool transparent = opacity <= 128;
10330
10331 if(rotation != 0) // rotate
10332 {
10333 draw_map_solidity(b, l, x1, y1);
10334
10335 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10336 script_drawing_commands.ReleaseSubBitmap(b);
10337 }
10338 else
10339 {
10340 BITMAP* square = create_bitmap_ex(8,16,16);
10341 for(int32_t i(0); i < 176; ++i)
10342 {
10343 const int32_t x2 = ((i&15)<<4) + x1;
10344 const int32_t y2 = (i&0xF0) + y1;
10345
10346 if(noclip && (x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10347 {
10348 clear_to_color(square,(combobuf[l.data[i]].walk&15));
10349 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10350 }
10351 }
10352 destroy_bitmap(square);
10353 }
10354
10355 //putscr
10356 }
10357
10358 void do_bmpdrawlayercflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10359 {
10360 //sdci[1]=layer
10361 //sdci[2]=map
10362 //sdci[3]=screen
10363 //sdci[4]=layer
10364 //sdci[5]=x
10365 //sdci[6]=y
10366 //sdci[7]=rotation
10367 //[8] noclip
10368 //sdci[9]=opacity
10369
10370
10371 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10372 int32_t scrn = sdci[3]/10000;
10373 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10374 int32_t x = sdci[5]/10000;
10375 int32_t y = sdci[6]/10000;
10376 int32_t x1 = x + xoffset;
10377 int32_t y1 = y + yoffset;
10378 int32_t rotation = sdci[7]/10000;
10379
10380 byte noclip = (sdci[8]!=0);
10381 int32_t opacity = sdci[9]/10000;
10382
10383 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10384 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10385
10386 if(!m) //no need to log it.
10387 return;
10388
10389 if(index >= TheMaps.size())
10390 {
10391 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10392 return;
10393 }
10394
10395 const mapscr & l = *m;
10396
10397 BITMAP* b = bmp;
10398
10399 if(rotation != 0)
10400 b = script_drawing_commands.AquireSubBitmap(256, 176);
10401
10402
10403 const int32_t maxX = isOffScreen ? 512 : 256;
10404 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10405 bool transparent = opacity <= 128;
10406
10407 if(rotation != 0) // rotate
10408 {
10409 draw_map_cflag(b, l, x1, y1);
10410
10411 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10412 script_drawing_commands.ReleaseSubBitmap(b);
10413 }
10414 else
10415 {
10416 BITMAP* square = create_bitmap_ex(8,16,16);
10417 for(int32_t i(0); i < 176; ++i)
10418 {
10419 const int32_t x2 = ((i&15)<<4) + x1;
10420 const int32_t y2 = (i&0xF0) + y1;
10421
10422 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10423 {
10424 clear_to_color(square,l.sflag[i]);
10425 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10426 }
10427 }
10428 destroy_bitmap(square);
10429 }
10430
10431 //putscr
10432 }
10433
10434 void do_bmpdrawlayerctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10435 {
10436 //sdci[1]=layer
10437 //sdci[2]=map
10438 //sdci[3]=screen
10439 //sdci[4]=layer
10440 //sdci[5]=x
10441 //sdci[6]=y
10442 //sdci[7]=rotation
10443 //[8] noclip
10444 //sdci[9]=opacity
10445
10446 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10447 int32_t scrn = sdci[3]/10000;
10448 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10449 int32_t x = sdci[5]/10000;
10450 int32_t y = sdci[6]/10000;
10451 int32_t x1 = x + xoffset;
10452 int32_t y1 = y + yoffset;
10453 int32_t rotation = sdci[7]/10000;
10454
10455 byte noclip = (sdci[8]!=0);
10456 int32_t opacity = sdci[9]/10000;
10457 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10458 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10459
10460 if(!m) //no need to log it.
10461 return;
10462
10463 if(index >= TheMaps.size())
10464 {
10465 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10466 return;
10467 }
10468
10469 const mapscr & l = *m;
10470
10471 BITMAP* b = bmp;
10472
10473 if(rotation != 0)
10474 b = script_drawing_commands.AquireSubBitmap(256, 176);
10475
10476
10477 const int32_t maxX = isOffScreen ? 512 : 256;
10478 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10479 bool transparent = opacity <= 128;
10480
10481 if(rotation != 0) // rotate
10482 {
10483 draw_map_combotype(b, l, x1, y1);
10484
10485 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10486 script_drawing_commands.ReleaseSubBitmap(b);
10487 }
10488 else
10489 {
10490 BITMAP* square = create_bitmap_ex(8,16,16);
10491 for(int32_t i(0); i < 176; ++i)
10492 {
10493 const int32_t x2 = ((i&15)<<4) + x1;
10494 const int32_t y2 = (i&0xF0) + y1;
10495
10496 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10497 {
10498 clear_to_color(square,(combobuf[l.data[i]].type));
10499 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10500 }
10501 }
10502 destroy_bitmap(square);
10503 }
10504
10505 //putscr
10506 }
10507
10508 void do_bmpdrawlayerciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10509 {
10510 //sdci[1]=layer
10511 //sdci[2]=map
10512 //sdci[3]=screen
10513 //sdci[4]=layer
10514 //sdci[5]=x
10515 //sdci[6]=y
10516 //sdci[7]=rotation
10517 //[8] noclip
10518 //sdci[9]=opacity
10519
10520 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10521 int32_t scrn = sdci[3]/10000;
10522 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
10523 int32_t x = sdci[5]/10000;
10524 int32_t y = sdci[6]/10000;
10525 int32_t x1 = x + xoffset;
10526 int32_t y1 = y + yoffset;
10527 int32_t rotation = sdci[7]/10000;
10528 byte noclip = (sdci[8]!=0);
10529 int32_t opacity = sdci[9]/10000;
10530
10531 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10532 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
10533
10534 if(!m) //no need to log it.
10535 return;
10536
10537 if(index >= TheMaps.size())
10538 {
10539 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
10540 return;
10541 }
10542
10543 const mapscr & l = *m;
10544
10545 BITMAP* b = bmp;
10546
10547 if(rotation != 0)
10548 b = script_drawing_commands.AquireSubBitmap(256, 176);
10549
10550
10551 const int32_t maxX = isOffScreen ? 512 : 256;
10552 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
10553 bool transparent = opacity <= 128;
10554
10555 if(rotation != 0) // rotate
10556 {
10557 draw_map_comboiflag(b, l, x1, y1);
10558
10559 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
10560 script_drawing_commands.ReleaseSubBitmap(b);
10561 }
10562 else
10563 {
10564 BITMAP* square = create_bitmap_ex(8,16,16);
10565 for(int32_t i(0); i < 176; ++i)
10566 {
10567 const int32_t x2 = ((i&15)<<4) + x1;
10568 const int32_t y2 = (i&0xF0) + y1;
10569
10570 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
10571 {
10572 clear_to_color(square,(combobuf[l.data[i]].flag));
10573 blit(square, b, 0, 0, x2, y2, square->w, square->h);
10574 }
10575 }
10576 destroy_bitmap(square);
10577 }
10578
10579 //putscr
10580 }
10581
10582
10583
10584 /////////////////////////////////////////////////////////
10585 // do primitives
10586 ////////////////////////////////////////////////////////
10587
10588 398550285 void do_primitives(BITMAP *targetBitmap, int32_t type, mapscr* theScreen, int32_t xoff, int32_t yoff)
10589 {
10590 398550285 color_map = &trans_table2;
10591
10592 //was this next variable ever used? -- DN
10593 //bool drawsubscr=false;
10594
10595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 398550285 times.
398550285 if(type > 7)
10596 return;
10597
3/4
✓ Branch 0 taken 126609771 times.
✓ Branch 1 taken 271940514 times.
✓ Branch 2 taken 126609771 times.
✗ Branch 3 not taken.
398550285 if(type >= 0 && theScreen->hidescriptlayers & (1<<type))
10598 return; //Script draws hidden for this layer
10599
2/2
✓ Branch 0 taken 3193497 times.
✓ Branch 1 taken 395356788 times.
398550285 if(!script_drawing_commands.is_dirty(type))
10600 395356788 return; //No draws to this layer
10601 //--script_drawing_commands[][] reference--
10602 //[][0]: type
10603 //[][1-16]: defined by type
10604 //[][17]: unused
10605 //[][18]: rendertarget
10606 //[][19]: unused
10607
10608 // Trying to match the old behavior exactly...
10609
2/2
✓ Branch 0 taken 932022 times.
✓ Branch 1 taken 2261475 times.
3193497 const bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0) || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
10610
10611 3193497 bool isTargetOffScreenBmp = false;
10612 3193497 const int32_t type_mul_10000 = type * 10000;
10613 3193497 const int32_t numDrawCommandsToProcess = script_drawing_commands.Count();
10614 3193497 FFCore.numscriptdraws = numDrawCommandsToProcess;
10615 3193497 int32_t xoffset=xoff, yoffset=yoff;
10616
2/2
✓ Branch 0 taken 297405852 times.
✓ Branch 1 taken 3193497 times.
300599349 for(int32_t i(0); i < numDrawCommandsToProcess; ++i)
10617 {
10618
2/2
✓ Branch 0 taken 23101383 times.
✓ Branch 1 taken 274304469 times.
297405852 if(!brokenOffset)
10619 {
10620 274304469 xoffset = 0;
10621 274304469 yoffset = 0;
10622 274304469 }
10623 297405852 int32_t *sdci = &script_drawing_commands[i][0];
10624
10625
2/2
✓ Branch 0 taken 198623251 times.
✓ Branch 1 taken 98782601 times.
297405852 if(sdci[1] != type_mul_10000)
10626 198623251 continue;
10627 // get the correct render target, if set.
10628 98782601 BITMAP *bmp = zscriptDrawingRenderTarget->GetTargetBitmap(sdci[18]);
10629
10630
2/2
✓ Branch 0 taken 6429021 times.
✓ Branch 1 taken 92353580 times.
98782601 if(!bmp)
10631 {
10632 // draw to screen with subscreen offset
10633
2/2
✓ Branch 0 taken 10176922 times.
✓ Branch 1 taken 82176658 times.
92353580 if(!brokenOffset)
10634 {
10635 82176658 xoffset = xoff;
10636 82176658 yoffset = yoff;
10637 82176658 }
10638 92353580 bmp = targetBitmap;
10639 92353580 }
10640 else
10641 {
10642 //not drawing to screen, so no subscreen offset
10643
2/2
✓ Branch 0 taken 6339401 times.
✓ Branch 1 taken 89620 times.
6429021 if(brokenOffset)
10644 {
10645 89620 xoffset = 0;
10646 89620 yoffset = 0;
10647 89620 }
10648 6429021 isTargetOffScreenBmp = true;
10649 }
10650
10651
40/82
✗ Branch 0 not taken.
✓ Branch 1 taken 2329703 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1130854 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1850 times.
✓ Branch 6 taken 2349855 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 404879 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1533969 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 2537283 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 5287220 times.
✓ Branch 18 taken 21409189 times.
✓ Branch 19 taken 962949 times.
✓ Branch 20 taken 142863 times.
✓ Branch 21 taken 1482101 times.
✓ Branch 22 taken 163717 times.
✓ Branch 23 taken 9266 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 928052 times.
✗ Branch 29 not taken.
✓ Branch 30 taken 4335769 times.
✓ Branch 31 taken 50406 times.
✓ Branch 32 taken 7971 times.
✗ Branch 33 not taken.
✓ Branch 34 taken 148823 times.
✗ Branch 35 not taken.
✓ Branch 36 taken 502 times.
✓ Branch 37 taken 144 times.
✗ Branch 38 not taken.
✓ Branch 39 taken 80910 times.
✓ Branch 40 taken 59816 times.
✗ Branch 41 not taken.
✓ Branch 42 taken 824 times.
✗ Branch 43 not taken.
✓ Branch 44 taken 167483 times.
✓ Branch 45 taken 32636464 times.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✓ Branch 48 taken 873 times.
✓ Branch 49 taken 45504 times.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✓ Branch 56 taken 1173 times.
✓ Branch 57 taken 1092 times.
✗ Branch 58 not taken.
✗ Branch 59 not taken.
✓ Branch 60 taken 1024 times.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✓ Branch 63 taken 266215 times.
✗ Branch 64 not taken.
✓ Branch 65 taken 113329 times.
✗ Branch 66 not taken.
✓ Branch 67 taken 3 times.
✓ Branch 68 taken 324166 times.
✓ Branch 69 taken 2790 times.
✓ Branch 70 taken 34653 times.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 73 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✓ Branch 76 taken 19821648 times.
✗ Branch 77 not taken.
✓ Branch 78 taken 6363 times.
✗ Branch 79 not taken.
✓ Branch 80 taken 906 times.
✗ Branch 81 not taken.
98782601 switch(sdci[0])
10652 {
10653 case RECTR:
10654 {
10655 2329703 do_rectr(bmp, sdci, xoffset, yoffset);
10656 }
10657 2329703 break;
10658 case FRAMER:
10659 {
10660 do_framer(bmp, sdci, xoffset, yoffset);
10661 }
10662 break;
10663
10664
10665 case CIRCLER:
10666 {
10667 1130854 do_circler(bmp, sdci, xoffset, yoffset);
10668 }
10669 1130854 break;
10670
10671 case ARCR:
10672 {
10673 do_arcr(bmp, sdci, xoffset, yoffset);
10674 }
10675 break;
10676
10677 case ELLIPSER:
10678 {
10679 1850 do_ellipser(bmp, sdci, xoffset, yoffset);
10680 }
10681 1850 break;
10682
10683 case LINER:
10684 {
10685 2349855 do_liner(bmp, sdci, xoffset, yoffset);
10686 }
10687 2349855 break;
10688
10689 case SPLINER:
10690 {
10691 do_spliner(bmp, sdci, xoffset, yoffset);
10692 }
10693 break;
10694
10695 case PUTPIXELR:
10696 {
10697 404879 do_putpixelr(bmp, sdci, xoffset, yoffset);
10698 }
10699 404879 break;
10700 case PIXELARRAYR:
10701 {
10702 //Z_scripterrlog("Reached case PIXELARRAYR\n");
10703 do_putpixelsr(bmp, i, sdci, xoffset, yoffset);
10704 }
10705 break;
10706
10707 case TILEARRAYR:
10708 {
10709 //Z_scripterrlog("Reached case PIXELARRAYR\n");
10710 do_fasttilesr(bmp, i, sdci, xoffset, yoffset);
10711 }
10712 break;
10713
10714 case LINESARRAY:
10715 {
10716 //Z_scripterrlog("Reached case PIXELARRAYR\n");
10717 do_linesr(bmp, i, sdci, xoffset, yoffset);
10718 }
10719 break;
10720
10721 case COMBOARRAYR:
10722 {
10723 //Z_scripterrlog("Reached case PIXELARRAYR\n");
10724 do_fastcombosr(bmp, i, sdci, xoffset, yoffset);
10725 }
10726 break;
10727
10728
10729
10730 case DRAWTILER:
10731 {
10732 1533969 do_drawtiler(bmp, sdci, xoffset, yoffset);
10733 }
10734 1533969 break;
10735
10736 case DRAWTILECLOAKEDR:
10737 {
10738 do_drawtilecloakedr(bmp, sdci, xoffset, yoffset);
10739 }
10740 break;
10741
10742 case DRAWCOMBOR:
10743 {
10744 2537283 do_drawcombor(bmp, sdci, xoffset, yoffset);
10745 }
10746 2537283 break;
10747
10748 case DRAWCOMBOCLOAKEDR:
10749 {
10750 do_drawcombocloakedr(bmp, sdci, xoffset, yoffset);
10751 }
10752 break;
10753
10754 case FASTTILER:
10755 {
10756 5287220 do_fasttiler(bmp, sdci, xoffset, yoffset);
10757 }
10758 5287220 break;
10759
10760 case FASTCOMBOR:
10761 {
10762 21409189 do_fastcombor(bmp, sdci, xoffset, yoffset);
10763 }
10764 21409189 break;
10765
10766 case DRAWCHARR:
10767 {
10768 962949 do_drawcharr(bmp, sdci, xoffset, yoffset);
10769 }
10770 962949 break;
10771
10772 case DRAWINTR:
10773 {
10774 142863 do_drawintr(bmp, sdci, xoffset, yoffset);
10775 }
10776 142863 break;
10777
10778 case DRAWSTRINGR:
10779 {
10780 1482101 do_drawstringr(bmp, i, sdci, xoffset, yoffset);
10781 }
10782 1482101 break;
10783
10784 case DRAWSTRINGR2:
10785 {
10786 163717 do_drawstringr2(bmp, i, sdci, xoffset, yoffset);
10787 }
10788 163717 break;
10789
10790 case QUADR:
10791 {
10792 9266 do_drawquadr(bmp, sdci, xoffset, yoffset);
10793 }
10794 9266 break;
10795
10796 case QUAD3DR:
10797 {
10798 do_drawquad3dr(bmp, i, sdci, xoffset, yoffset);
10799 }
10800 break;
10801
10802 case TRIANGLER:
10803 {
10804 do_drawtriangler(bmp, sdci, xoffset, yoffset);
10805 }
10806 break;
10807
10808 case TRIANGLE3DR:
10809 {
10810 do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset);
10811 }
10812 break;
10813
10814 case POLYGONR:
10815 {
10816 do_polygonr(bmp, i, sdci, xoffset, yoffset);
10817 }
10818 break;
10819
10820
10821 case BITMAPR:
10822 {
10823 928052 do_drawbitmapr(bmp, sdci, xoffset, yoffset);
10824 }
10825 928052 break;
10826
10827 case BITMAPEXR:
10828 {
10829 do_drawbitmapexr(bmp, sdci, xoffset, yoffset);
10830 }
10831 break;
10832
10833 case DRAWLAYERR:
10834 {
10835 4335769 do_drawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
10836 }
10837 4335769 break;
10838
10839 case DRAWSCREENR:
10840 {
10841 50406 do_drawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
10842 }
10843 50406 break;
10844
10845 7971 case BMPRECTR: bmp_do_rectr(bmp, sdci, xoffset, yoffset); break;
10846 case BMPFRAMER: bmp_do_framer(bmp, sdci, xoffset, yoffset); break;
10847 148823 case BMPCIRCLER: bmp_do_circler(bmp, sdci, xoffset, yoffset); break;
10848 case BMPARCR: bmp_do_arcr(bmp, sdci, xoffset, yoffset); break;
10849 502 case BMPELLIPSER: bmp_do_ellipser(bmp, sdci, xoffset, yoffset); break;
10850 144 case BMPLINER: bmp_do_liner(bmp, sdci, xoffset, yoffset); break;
10851 case BMPSPLINER: bmp_do_spliner(bmp, sdci, xoffset, yoffset); break;
10852 80910 case BMPPUTPIXELR: bmp_do_putpixelr(bmp, sdci, xoffset, yoffset); break;
10853 59816 case BMPDRAWTILER: bmp_do_drawtiler(bmp, sdci, xoffset, yoffset); break;
10854 case BMPDRAWTILECLOAKEDR: bmp_do_drawtilecloakedr(bmp, sdci, xoffset, yoffset); break;
10855 824 case BMPDRAWCOMBOR: bmp_do_drawcombor(bmp, sdci, xoffset, yoffset); break;
10856 case BMPDRAWCOMBOCLOAKEDR: bmp_do_drawcombocloakedr(bmp, sdci, xoffset, yoffset); break;
10857 167483 case BMPFASTTILER: bmp_do_fasttiler(bmp, sdci, xoffset, yoffset); break;
10858 32636464 case BMPFASTCOMBOR: bmp_do_fastcombor(bmp, sdci, xoffset, yoffset); break;
10859 case BMPDRAWCHARR: bmp_do_drawcharr(bmp, sdci, xoffset, yoffset); break;
10860 case BMPDRAWINTR: bmp_do_drawintr(bmp, sdci, xoffset, yoffset); break;
10861 873 case BMPDRAWSTRINGR: bmp_do_drawstringr(bmp, i, sdci, xoffset, yoffset); break;
10862 45504 case BMPDRAWSTRINGR2: bmp_do_drawstringr2(bmp, i, sdci, xoffset, yoffset); break;
10863 case BMPQUADR: bmp_do_drawquadr(bmp, sdci, xoffset, yoffset); break;
10864 case BMPQUAD3DR: bmp_do_drawquad3dr(bmp, i, sdci, xoffset, yoffset); break;
10865
10866 case BITMAPGETPIXEL: bmp_do_getpixelr(bmp, sdci, xoffset, yoffset); break;
10867 case BMPTRIANGLER: bmp_do_drawtriangler(bmp, sdci, xoffset, yoffset); break;
10868 case BMPTRIANGLE3DR: bmp_do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset); break;
10869 case BMPPOLYGONR: bmp_do_polygonr(bmp, i, sdci, xoffset, yoffset); break;
10870 1173 case BMPDRAWLAYERR: do_bmpdrawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10871 1092 case BMPDRAWSCREENR: do_bmpdrawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10872 case BMPDRAWSCREENSOLIDR: do_bmpdrawscreen_solidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10873 case BMPDRAWSCREENSOLID2R: do_bmpdrawscreen_solidr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10874 1024 case BMPDRAWSCREENCOMBOFR: do_bmpdrawscreen_cflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10875 case BMPDRAWSCREENCOMBOIR: do_bmpdrawscreen_ciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10876 case BMPDRAWSCREENCOMBOTR: do_bmpdrawscreen_ctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10877 266215 case BMPBLIT: bmp_do_drawbitmapexr(bmp, sdci, xoffset, yoffset); break;
10878 case BMPMODE7: bmp_do_mode7r(bmp, sdci, xoffset, yoffset); break;
10879 113329 case BMPBLITTO: bmp_do_blittor(bmp, sdci, xoffset, yoffset); break;
10880 case READBITMAP: bmp_do_readr(bmp, i, sdci, xoffset, yoffset); break;
10881 3 case WRITEBITMAP: bmp_do_writer(bmp, i, sdci, xoffset, yoffset); break;
10882 324166 case CLEARBITMAP: bmp_do_clearr(bmp, sdci, xoffset, yoffset); break;
10883 2790 case BITMAPCLEARTOCOLOR: bmp_do_clearcolorr(bmp, sdci, xoffset, yoffset); break;
10884 34653 case REGENERATEBITMAP: bmp_do_regenr(bmp, sdci, xoffset, yoffset); break;
10885
10886 case BMPDRAWLAYERSOLIDR: do_bmpdrawlayersolidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10887 case BMPDRAWLAYERCFLAGR: do_bmpdrawlayercflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10888 case BMPDRAWLAYERCTYPER: do_bmpdrawlayerctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10889 case BMPDRAWLAYERCIFLAGR: do_bmpdrawlayerciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10890 case BMPDRAWLAYERSOLIDITYR: do_bmpdrawlayersolidityr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
10891 19821648 case BMPWRITETILE: do_bmpwritetile(bmp, sdci, xoffset, yoffset); break;
10892 case BMPDITHER: do_bmpdither(bmp, sdci, xoffset, yoffset); break;
10893 6363 case BMPREPLCOLOR: do_bmpreplcol(bmp, sdci, xoffset, yoffset); break;
10894 case BMPSHIFTCOLOR: do_bmpshiftcol(bmp, sdci, xoffset, yoffset); break;
10895 906 case BMPMASKDRAW: do_bmpmaskdraw(bmp, sdci, xoffset, yoffset); break;
10896 case BMPMASKBLIT: do_bmpmaskblit(bmp, sdci, xoffset, yoffset); break;
10897 }
10898 98782601 }
10899
10900
10901 3193497 color_map=&trans_table;
10902 398550285 }
10903
10904 16074652 void CScriptDrawingCommands::Clear()
10905 {
10906 16074652 scb.update();
10907 16074652 dirty_layers.clear();
10908
2/2
✓ Branch 0 taken 11450751 times.
✓ Branch 1 taken 4623901 times.
16074652 if(commands.empty())
10909 11450751 return;
10910
10911 //only clear what was used.
10912 4623901 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
10913 4623901 count = 0;
10914
10915 4623901 draw_container.Clear();
10916 16074652 }
10917 CScriptDrawingCommands* CScriptDrawingCommands::pop_commands()
10918 {
10919 CScriptDrawingCommands* ret = new CScriptDrawingCommands();
10920 if(commands.empty())
10921 return ret;
10922 ret->push_commands(this, false);
10923
10924 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
10925 count = 0;
10926
10927 draw_container.Clear();
10928 return ret;
10929 }
10930 void CScriptDrawingCommands::push_commands(CScriptDrawingCommands* other, bool del)
10931 {
10932 commands.insert(commands.end(), other->commands.begin(), other->commands.end());
10933 count += other->count;
10934 if(del) delete other;
10935 }
10936
10937 148956 void do_script_draws(BITMAP *targetBitmap, mapscr* theScreen, int32_t xoff, int32_t yoff, bool hideLayer7)
10938 {
10939
2/2
✓ Branch 0 taken 147962 times.
✓ Branch 1 taken 994 times.
148956 if(XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
10940
2/2
✓ Branch 0 taken 147138 times.
✓ Branch 1 taken 1818 times.
148956 if(XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
10941 148956 do_primitives(targetBitmap, 0, theScreen, xoff, yoff);
10942 148956 do_primitives(targetBitmap, 1, theScreen, xoff, yoff);
10943
2/2
✓ Branch 0 taken 994 times.
✓ Branch 1 taken 147962 times.
148956 if(!XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
10944
2/2
✓ Branch 0 taken 1818 times.
✓ Branch 1 taken 147138 times.
148956 if(!XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
10945 148956 do_primitives(targetBitmap, 4, theScreen, xoff, yoff);
10946 148956 do_primitives(targetBitmap, 5, theScreen, xoff, yoff);
10947 148956 do_primitives(targetBitmap, 6, theScreen, xoff, yoff);
10948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148956 times.
148956 if(!hideLayer7) do_primitives(targetBitmap, 7, theScreen, xoff, yoff);
10949 148956 }
10950